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

How to draw the flowchart for structure programs?

8821


What are the functions to open and close file in c language?

795


Can you please explain the scope of static variables?

666


Can we change the value of static variable in c?

627


Which operators cannot be overloaded a) Sizeof b) .* c) :: d) all of the above

732






What are the c keywords?

820


What are high level languages like C and FORTRAN also known as?

766


What are pointers? What are different types of pointers?

691


What is define c?

645


What is build process in c?

711


Compare array data type to pointer data type

670


What is the difference between pure virtual function and virtual function?

713


What is integer constants?

688


In a byte, what is the maximum decimal number that you can accommodate?

703


What is putchar() function?

696