Wednesday 1 January 2014

c++ program for comparing two numbers without using relational operators

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c;
clrscr();
cout<<"enter any two integers";
cin>>a>>b;
c=a-b;
if(!c)
{
        //if c is zero
cout<<"both are equal";
}
else if(c-abs(c))
 {
/if c returns a -ve value
cout<<"b is greater..";
 }
else
{
//if c returns a +ve value
cout<<"a is greater..";
}
getch();
}

No comments:

Post a Comment