Home » Add Two Numbers Without Using the Addition Operator in C

Add Two Numbers Without Using the Addition Operator in C

Learn about Add Two Numbers Without Using the Addition Operator in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Contents

Add Two Numbers Without Using the Addition Operator in C

Program:

#include<stdio.h>
#include<math.h>
int main()
{
  int x, y;
  printf("Enter two number: ");
  scanf("%d %d",&x,&y);

  printf("%d\n", x-(-y));

  // method 2
  printf("%d\n", -(-x-y));

  // method 3
  printf("%d\n", abs(-x-y));

  // method 4
  printf("%d", x-(~y)-1);

  return 0;
}

Output:

Enter two number: 3 5
8
8
8
8

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C program to find LCM using recursion
C program to find gcd of two numbers using recursion