difference of two no's with out using - operator
Answers were Sorted based on User's Feedback
Answer / arpit
void count()
{
int c=0;
for(i=a;i<=b;i++)
{
c++;
}
return(c);
}
c=b-a :...easy and best .....
Is This Answer Correct ? | 10 Yes | 5 No |
Answer / gg
Try this....
main()
{
int a,b;
printf("Enter two integers \n");
scanf("%d%d",&a,&b);
printf("The diff is : %d ",a+(~b+1));
}
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / supri
see subtraction itself is the addition of the number with
its 2's complement....
add(int a,int b)
{
if(!a)
return b;
else
return(add((a&b)<<1,a^b));
}
main()
{
int a,b;
scanf("%d%d",&a,&b);
b=add(~b,1);
printf("%d",add(a,b));
return;
}
u can try this...
Is This Answer Correct ? | 2 Yes | 1 No |
#include<stdio.h>
#include<conio.h>
//To calculate a-b
void main()
{
int a,b,min,max;
printf("Enter the value of a and b \n");
scanf("%d %d",&a,&b);
min = (a<b)?a:b;
max = (a>b)?a:b;
while(min--) max--;
if(a<b)
printf("-%d",max);
else
printf("%d",max);
}
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sandeep
int count(int a , int b)
{
int c=0;
if(a<b)
for(i=a;i<=b;i++)
{
c++;
}
else
for(i=b;i<=a;i++)
{
c++;
}
return(c); }
www.NSITFORUM.co.cc
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / dally
#include<stdio.h>
int main()
{
int a=9,b=4;
if(a>b)
{
while(a--)
b = b--;
}
else
printf("Difference is not possible\n") ;
}
Is This Answer Correct ? | 0 Yes | 2 No |
Answer / vignesh1988i
its simple logic , wat i think is to AND these two inputs.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,m;
scanf("%d %d",&m,&n);
if(m>n)
printf("%d",m&n);
else
printf("%d",n&m);
getch();
}
thank u
Is This Answer Correct ? | 1 Yes | 10 No |
How can I avoid the abort, retry, fail messages?
What is pointers in c with example?
What is keyword with example?
write program on arrays
What is a double c?
write a program without using main function?
How a string is stored in c?
do you think its fraud or original company?
Explain how do you print an address?
what is the difference between call by value and call by reference?
5 Answers Genpact, Global Logic, Infosys,
In which language linux is written?
write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.
0 Answers Lovely Professional University,