C Program Addition and Subtraction without using + – Operators

By | 2018-04-15T06:20:18+00:00 April 15th, 2018|c-program|0 Comments

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

C Program Addition :

#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:

10+20 = 30

C Program Subtration :

#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:

10 - 20 = -10

Happy Learning 🙂

About the Author:

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Leave A Comment