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?

Answers were Sorted based on User's Feedback



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

Answer / bashu

main()
{
int x,y;
sf("%d,%d",&x,&y);
if(x^y)
pf("not equal");
else
pf("equal");
}

Is This Answer Correct ?    39 Yes 22 No

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

Answer / faceless

main()
{
int result, sign_bit_num;
unsigned int x, y;

sign_bit_num = sizeof(int)*8 ;

result = x-y;

if (result) {
result = result >> (sign_bit_num-1);

if (result) {
printf("x less than y");
} else {
printf("x greater than y");
}
} else {
printf("equal");
}

Is This Answer Correct ?    14 Yes 8 No

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

Answer / 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

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

Answer / jj

unsigned int is_same(unsigned int a, unsigned int b)
{
return (a / b);
}

int main()
{
unsigned int a, b;
a = 40, b = 40;

if ( is_same(a,b) == 1 )?
cout << "Equal" << endl
:
cout << "Not equal" << endl;
return 0;
}

Is This Answer Correct ?    0 Yes 5 No

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

Answer / r.aruna

#include<stdio.h>
#include<conio.h>
void main()
{
int a;
int b;
clrscr();
printf("enter the a value=");
scanf("%d",&a);
printf("enter the b value=");
scanf("%d",&b);
if(a==b)
{
printf("a is greater");
}
else
{
printf("b is greater");
}
getch();
}

Is This Answer Correct ?    4 Yes 15 No

Post New Answer

More C Interview Questions

What is sizeof array in c?

0 Answers  


Write a program to print distinct words in an input along with their count in input in decreasing order of their count

0 Answers  


totally how much header files r in c language

8 Answers   TCS,


How variables are declared in c?

0 Answers  


What is memmove?

1 Answers   Oracle,


When is a null pointer used?

0 Answers  


How to reverse a linked list

1 Answers   Aricent, Fidelity, IBM, TCS,


What does the message "warning: macro replacement within a string literal" mean?

1 Answers  


c program to arrange digits in a no in ascending and descending order

1 Answers  


Is array name a pointer?

0 Answers  


Can the “if” function be used in comparing strings?

0 Answers  


Explain how can a program be made to print the line number where an error occurs?

0 Answers  


Categories