Thursday 6 August 2015

Smallest of three integers without comparison operators

#include<stdio.h>
 
int smallest(int x, int y, int z)
{
  int c = 0;
  while ( x && y && z )
  {
      x--;  y--; z--; c++;
  }
  return c;
}
 
int main()
{
   int x = 12, y = 15, z = 5;
   printf("Minimum of 3 numbers is %d", smallest(x, y, z));
   return 0;
}

Leave a Reply

 
 

Labels

Blog Archive