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


Please Help Members By Posting Answers For Below Questions

What are the keywords in c?

855


What is bubble sort technique in c?

755


What are the difference between a free-standing and a hosted environment?

993


Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

15428


What is the size of empty structure in c?

804


What is a built-in function in C?

1088


which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +

1460


What is a pragma?

863


Explain the ternary tree?

786


What is the use of typedef in c?

772


What do header files do?

804


write a program using linked list in which each node consists of following information. Name[30] Branch Rollno Telephone no i) Write the program to add information of students in linked list

2512


What is data type long in c?

823


Discuss the function of conditional operator, size of operator and comma operator with examples.

873


What is .obj file in c?

829