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 far and near in c?
Write the syntax and purpose of a switch statement in C.
Can variables be declared anywhere in c?
What does the function toupper() do?
Explain how do you print an address?
What is the code in while loop that returns the output of given code?
the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?
What are global variables?
What is the use of header files?
What is the condition that is applied with ?: Operator?
how should functions be apportioned among source files?
What is the difference between struct and typedef struct in c?
What does printf does?
What is hashing in c language?
What is the full form of getch?