Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write a program to compare 2 numbers without using logical
operators?

Answer Posted / rishabh

#include<stdio.h>
#include<limits.h>
int sign(int number)
{
return (unsigned) number / (unsigned) INT_MIN;
}
int main(int argc, char *argv[])
{
int a = atoi(argv[1]);
int b = atoi(argv[2]);
int dif = a - b;
int sb1 = sign(dif);
int sb2 = sign(dif - 1) - sb1;
int ptr = 2 * sb2 + sb1;
char *messages[3] =
{
"%d is greater than %d",
"%d is less than %d",
"%d is equal to %d" };
printf(messages[ptr], a, b);
}
}

Is This Answer Correct ?    3 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

List some applications of c programming language?

959


How many types of operator or there in c?

1101


what are non standard function in c

1917


my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?

1593


In c language can we compile a program without main() function?

1143


What would be an example of a structure analogous to structure c?

1002


What are the various types of control structures in programming?

1064


In C programming, what command or code can be used to determine if a number of odd or even?

1067


Explain the difference between #include "..." And #include <...> In c?

1037


What is meant by keywords in c?

1074


Is printf a keyword?

1210


Is stack a keyword in c?

1094


`write a program to display the recomended action depends on a color of trafic light using nested if statments

2137


What will be your course of action for a push operation?

1113


What are the properties of union in c?

1055