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

Simplify the program segment if X = B then C ← true else C ← false

2575


Dont ansi function prototypes render lint obsolete?

599


Explain what is the benefit of using an enum rather than a #define constant?

712


What does c in a circle mean?

572


I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.

1733






What is a structure and why it is used?

613


How does normalization of huge pointer works?

619


Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.

615


a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above

648


Where in memory are my variables stored?

626


Tell us something about keyword 'auto'.

657


Why is c platform dependent?

612


What is pointers in c with example?

573


Explain the difference between call by value and call by reference in c language?

637


What is file in c preprocessor?

646