#include <stdio.h> int main() { int num1, num2, max, min; printf("Enter two numbers: "); scanf("%d %d", &num1, &num2); max = num1 - ((num1 - num2) & ((num1 - num2) >> (sizeof(int) * 8 - 1))); min = num2 + ((num1 - num2) & ((num1 - num2) >> (sizeof(int) * 8 - 1))); printf("Maximum: %d\n", max); printf("Minimum: %d\n", min); return 0; }
Inside the main() function:
- Integer variables `num1`, `num2`, `max`, and `min` are declared to store the input numbers and the maximum and minimum of the two numbers respectively.
- The user is prompted to enter two numbers.
- The maximum of the two numbers is calculated using bitwise operations without using any loops or conditions.
- Similarly, the minimum of the two numbers is calculated.
- Finally, the program prints the maximum and minimum values.