C Program To Add without Addition Operator

Ram Pothuraju

This is a simple  Program in C to print sum or addition of two numbers without using Arithmetical operators.  It is mostly asked in Interviews. 


Add without Arithmetic Operators
#include <stdio.h>
#include <iostream.h>
int main()
{
int a=7,b=5;
while(b--) // b will take value 5,4,3,2,1,0
a++;    // a will take values 7,8,9,10,11,12

cout<<a;
}

Here what we have done is that we have run a added the number 1 or incremented the value of variable by 1 and decremented the other by 1 till the decremented variable is 0.
The number of times the loop runs for 'b', that many times the value of a will increase.

Post a Comment

0Comments

Post a Comment (0)