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 is integer constants?

613


What does the error 'Null Pointer Assignment' mean and what causes this error?

737


Is a house a mass structure?

636


In C language what is a 'dangling pointer'?

632


How can I find out if there are characters available for reading?

637






write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34

1623


What is the right type to use for boolean values in c?

580


Explain what is the difference between a free-standing and a hosted environment?

631


Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

2116


Who developed c language and when?

573


What is an lvalue in c?

690


What are the types of unary operators?

656


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

680


Explain the use of keyword 'register' with respect to variables.

586


Why static variable is used in c?

548