Header Ads

WAP to print Greatest of Two Numbers using Bitwise Operators in C - 47

This program prints the Greatest of two Numbers without using if statement, but by making use of the BitWise Operators.

Program Code:

/* program to find the greatest of two numbers without using if statement. */

#include 
int main()
{
        int num1, num2, max;

        printf("Enter Num-1 value : ");
        scanf("%d", &num1);

        printf("Enter Num-2 value : ");
        scanf("%d", &num2);
 
        printf("Method 1 : \n");
        max = num1 > num2 ? num1 : num2;
        printf("%d is the Maximum\n", max);

        printf("Method 2 : \n");
        max = ((num1 + num2) + abs(num1 - num2))/2;
        printf(" %d is the Maximum\n", max);

        return 0;
}

Program Output:

No comments