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
How many keywords (reserve words) are in c?
Suggesting that there can be 62 seconds in a minute?
Why c is called object oriented language?
What is actual argument?
How can I discover how many arguments a function was actually called with?
what are non standard function in c
what is the different bitween abap and abap-hr?
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
how to introdu5ce my self in serco
What is the difference between null pointer and wild pointer?
Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor
What is pragma c?
How do I round numbers?
Linked list is a Linear or non linear explain if linear how it working as a non linear data structures
What is #include cctype?