Friday, September 7, 2012

Finding if two numbers are of same sign or opposite sign without using arithmetic operators


#include<stdio.h>

int ifopposite(int a,int b){
return ((a^b) < 0)?1:0;
}

int main(){
int a=-5;
int b=6;
if(ifopposite(a,b)){
printf("numbers are of opposite sign");
} else {
printf("numbers are of same sign");
}
return 0;
}

No comments:

Post a Comment