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
I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...
Write a program of advanced Fibonacci series.
Why use int main instead of void main?
What does d mean?
What does a pointer variable always consist of?
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
What does do in c?
Why double pointer is used in c?
What does *p++ do?
What does 3 periods mean in texting?
what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9
How can you find out how much memory is available?
Explain 'bus error'?
What is the use of the function in c?
How to get string length of given string in c?