Monday 18 February 2013

C/C++ Puzzles: PART - 19

  Finding the Sum without using Addition Operator

  C/C++ puzzles often include problems which can be solved by correctly applying the properties of various Mathematical Operators. I have come across the following problem recently. Find the sum of two numbers without using the addition operator (+). The solution is given below. The solution does not depend on the intricacies of C/C++ Language; it merely uses the basic properties of Arithmetical Operators.

#include<stdio.h>

int main()
{
    int a,b,c;
    printf("Enter the Two Numbers:\n");
    scanf("%d%d",&a,&b);
    c=a-(-b);
    printf("\nThe Sum = %d\n",c);
    return 0;
}


No comments:

Post a Comment