difference of two no's with out using - operator

Answers were Sorted based on User's Feedback



difference of two no's with out using - operator..

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

difference of two no's with out using - operator..

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

difference of two no's with out using - operator..

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

difference of two no's with out using - operator..

Answer / santhi perumal

#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

difference of two no's with out using - operator..

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

difference of two no's with out using - operator..

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

difference of two no's with out using - operator..

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

Post New Answer

More C Interview Questions

How can I avoid the abort, retry, fail messages?

0 Answers  


What is pointers in c with example?

0 Answers  


What is keyword with example?

0 Answers  


write program on arrays

3 Answers   GE, Polycab,


What is a double c?

0 Answers  






write a program without using main function?

2 Answers   TCS,


How a string is stored in c?

0 Answers  


do you think its fraud or original company?

0 Answers  


Explain how do you print an address?

0 Answers  


what is the difference between call by value and call by reference?

5 Answers   Genpact, Global Logic, Infosys,


In which language linux is written?

0 Answers  


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,


Categories