sir i wanted to know how we wap in c to add numbers without
using arithmetic operator in which digits are entered by
user?
Answer Posted / niranjan vg
#include<stdio.h>
int main()
{
int a,b,sum,carry;
printf("\n Enter the numbers : ");
scanf("%d%d",&a,&b);
sum=a^b;
carry=a&b; // Produce a extra carry bit if present
while(carry!=0)
{
carry<<=1; // shift for every iteration so
that it gets added with the next digit
a=sum;
b=carry;
sum=a^b; // perform Xor Operation
carry=a&b; // Calculate the new value for carry
}
printf("\n The sum is %d", sum);
}
Is This Answer Correct ? | 3 Yes | 1 No |
Post New Answer View All Answers
I have a varargs function which accepts a float parameter?
Is fortran still used in 2018?
Why is c so important?
Explain what happens if you free a pointer twice?
How can I implement a delay, or time a users response, with sub-second resolution?
What are the advantages of c preprocessor?
What does c mean in standard form?
What are different storage class specifiers in c?
Explain setjmp()?
What is the best style for code layout in c?
If you know then define #pragma?
What does %2f mean in c?
Explain what is the advantage of a random access file?
What do header files do?
Explain the use of #pragma exit?