write a program to compare 2 numbers without using logical
operators?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
write a program that will print %d in the output screen??
An interactive c program to read basic salary of 15 persons. each person gets 25% of basic as HRA, 15%of basic as conveyance allowances, 10%of basic as entertainment allowances.The total salary is calculated by adding basic+HRA+CA+EA.Calculate how many out of 15 get salary above 10,000.Rs also print the salary of each employee
How to explain the final year project as a fresher please answer with sample project
Study the code: void show() main() { show(); } void show (char *s) { printf("%sn",s); } What will happen if it is compiled & run on an ANSI C Compiler? A)It will compile & nothing will be printed when it is executed B)it will compile but not link C)the compiler will generate an error D)the compiler will generate a warning
why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above
Why we use int main and void main?
What is the output of the program given below #include<stdio.h> main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
21 Answers ADITI, Student, TCS,
What will be result of the following program? void myalloc(char *x, int n) { x= (char *)malloc(n*sizeof(char)); memset(x,\0,n*sizeof(char)); } main() { char *g="String"; myalloc(g,20); strcpy(g,"Oldstring"); printf("The string is %s",g); } a) The string is : String b) Run time error/Core dump c) The string is : Oldstring d) Syntax error during compilation e) None of these
Dear Sir, we are required the bubble sorting programs Regs Prem
Who is invented by c?
What is the purpose of type declarations?
What is assignment operator?