- Back to Home »
- Smallest of Three Integers without Using Comparison Operators (C Program)
Posted by : Unknown
#include<stdio.h>#define CHAR_BIT 8/*Function to find minimum of x and y*/int min(int x, int y){return y + ((x - y) & ((x - y) >>(sizeof(int) * CHAR_BIT - 1)));}/* Function to find minimum of 3 numbers x, y and z*/int smallest(int x, int y, int z){return min(x, min(y, z));}int main(){int x = 12, y = 15, z = 5;printf("Minimum of 3 numbers is %d", smallest(x, y, z));return 0;}