Thursday, November 7
Smallest of integers alternate approach
//code by http://CppQA.blogspot.com
//we are community of developers focusing on help for new programmers
#include <iostream>
using namespace std;
#define CHAR_BIT 8
/*Function to find minimum of x and y*/
int min(int x, int y)
{
return x + ((y - x) & ((y - x) >>
(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 = 1, y = 100, z = 90;
cout << "Minimum of 3 numbers is " << smallest(x, y, z) << endl<<"http://CppQA.blogspot.com"<<endl;
return 0;
}
you can fork this code on ideone.com
hi my name is umar
but ideone is not completely free
ReplyDeleteidone and both are good but we can fork it using ideone
ReplyDeletei like ideone
ReplyDeleteold one :D
ReplyDeletebtw which one is better the old one or new from ideone people, i like both of these
ReplyDeletei never saw that ideone.com has wrapped the lines
ReplyDelete