Google Add

Search

Write a Program to Add Two Numbers Without Using Addition Operator


To add two numbers without using Addition Operator

Logic


while(b--)
     a++;

In this logic i decrement one number and increment another one. Suppose two 
numbers a and b. The value of a=4 and b=5. As per logic while b is not zero, a will increment.




Solution

#include<stdio.h>

void main()
{
  int a=4,b=5;
 
  while(b--)
     a++;

  printf("The sum of two numbers is %d",a);

}

Some more tricky questions

Problem on Linked List


No comments:

Post a Comment