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


Please Help Members By Posting Answers For Below Questions

I have a varargs function which accepts a float parameter?

562


Is fortran still used in 2018?

580


Why is c so important?

584


Explain what happens if you free a pointer twice?

595


How can I implement a delay, or time a users response, with sub-second resolution?

610






What are the advantages of c preprocessor?

694


What does c mean in standard form?

587


What are different storage class specifiers in c?

602


Explain setjmp()?

641


What is the best style for code layout in c?

618


If you know then define #pragma?

661


What does %2f mean in c?

662


Explain what is the advantage of a random access file?

648


What do header files do?

593


Explain the use of #pragma exit?

681