How to add two numbers without using arithmetic operators?
Answer Posted / selloorhari
#include <stdio.h>
int add(int a, int b)
{
if (!a)
return b;
else
return add((a & b) << 1, a ^ b);
}
int main()
{
unsigned int a,b;
printf("Enter the two numbers: \n");
scanf("%d",&a);
scanf("%d",&b);
printf("Sum is: %d",add(a,b));
}
| Is This Answer Correct ? | 168 Yes | 30 No |
Post New Answer View All Answers
What is getch?
What is difference between function overloading and operator overloading?
What type is sizeof?
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.
Can a function argument have default value?
Explain how can I write functions that take a variable number of arguments?
What is static identifier?
How to delete a node from linked list w/o using collectons?
Describe the steps to insert data into a singly linked list.
What's the best way of making my program efficient?
What do you mean by a local block?
What is calloc() function?
Explain what is the concatenation operator?
What is array within structure?
a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list