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
What is the difference between the expression “++a” and “a++”?
How can I split up a string into whitespace-separated fields?
What library is sizeof in c?
What is structure padding and packing in c?
What is methods in c?
What does double pointer mean in c?
Explain what will the preprocessor do for a program?
i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none
What does void main return?
What is spark map function?
What is c language used for?
Is register a keyword in c?
State the difference between x3 and x[3].
Explain what is a const pointer?
What are the types of type qualifiers in c?