difference of two no's with out using - operator

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why static is used in c?

614


Do you know what are bitwise shift operators in c programming?

577


write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34

1620


Why doesnt this code work?

609


How can I find the modification date and time of a file?

596






What is a double c?

580


Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented Input: 11:30 Output: 13:10 Input: 18:25 Output: 21:58

1113


What are the data types present in c?

617


how to write a c program to print list of fruits in alpabetical order?

1782


Who invented b language?

905


What is meant by type casting?

618


Is int a keyword in c?

550


what do you mean by inline function in C?

605


Can a file other than a .h file be included with #include?

675


What does %p mean c?

617