We can do addition and subtraction without using +,- operators in C Language.

C Program Addition :

Addition.c
#include<stdio.h>
 int addition(int x, int y) {
   int a, b;
   do {
     a = x & y;
     b = x ^ y;
     x = a << 1;
     y = b;
   } while (a);
   return b;
 }
 int main(void) {
   printf("10+20 = %d", addition(10, 20));
   return 0;
 }

Output:

Terminal
10+20 = 30

C Program Subtration :

Sub.c
#include<stdio.h> 

int sub(int x, int y) {
  unsigned a, b;
  do {
    a = ~x & y;
    b = x ^ y;
    x = b;
    y = a << 1;
  } while (a);
  return b;
}
int main(void) {
  printf("10 - 20 = %d", sub(10, 20));
  return 0;
}

Output:

Terminal
10 - 20 = -10

Happy Learning 🙂

About the Author:

Avatar
Founder of onlinetutorialspoint.com Love Java, Python, Shell and opensource frameworks. Follow him on twitter and facebook for latest updates.

Leave A Comment