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

What is the function of multilevel pointer in c?

1044


Where is c used?

1046


Explain the difference between malloc() and calloc() function?

1003


Write a program to implement queue.

1083


How many levels deep can include files be nested?

1115


What are different types of operators?

1000


What is static and volatile in c?

1194


What are the header files used in c language?

1007


When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

1228


What are the disadvantages of external storage class?

1021


Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me

1916


Can a pointer be volatile in c?

957


What is a sequential access file?

1123


When the macros gets expanded?

1361


Difference between linking and loading?

1077