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

how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

0 Answers   TCS,


Can I initialize unions?

0 Answers  


What is sizeof int?

0 Answers  


what is the difference between normal variables and pointer variables..............

15 Answers   HP, Infosys, Satyam, Vivekanand Education Society,


what would be the output of the following program? main() { int k = 123; char *ptr; ptr = &k; printf("%d",*ptr); }

4 Answers  






What is pointers in c?

0 Answers  


the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+....

2 Answers   Ignou,


What is bss in c?

0 Answers  


When should a type cast be used?

0 Answers  


#include<stdio.h> int fun(); int i; int main() { while(i) { fun(); main(); } printf("hello \n"); return 0; } int fun() { printf("hi"); } answer is hello.how??wat is tat while(i) mean?

7 Answers   Intel,


Why c is called object oriented language?

0 Answers  


simple c program for 12345 convert 54321 with out using string

7 Answers   TCS,


Categories