Learn How To Add Two Numbers without using Plus (+) Operator in C Programming Language. We generally use plus operator (+) to find the sum of two numbers. Here, we shall use the postfix operator (—) to find the sum of the numbers. Alternatively, two numbers can be added using Bitwise Operators.
The first code to find the sum of two numbers without using arithmetic operator makes use of the postfix or decrement (—) operator. If you want to add two integers without arithmetic operators, then you will have to use the bitwise operators which is demonstrated in the second program.
C Program To Add Two Numbers without using Plus Operator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include<stdio.h> int main() { int a, b, num1, num2; printf("\nEnter First Number:\t"); scanf("%d", &num1); printf("\nEnter Second Number:\t"); scanf("%d", &num2); a = num1; b = num2; while(num2--) { num1 = num1 + 1; } printf("\nAddition of Two Numbers %d and %d:\t%d\n", a, b, num1); return 0; } |
C Program To Add Two Numbers using Bitwise Operators
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include<stdio.h> int main() { int a, b, num1, num2, carry, sum; printf("\nEnter First Number:\t"); scanf("%d", &num1); printf("\nEnter Second Number:\t"); scanf("%d", &num2); a = num1; b = num2; while (num2 != 0) { carry = num1 & num2; num1 = num1 ^ num2; num2 = carry << 1; } printf("\nAddition of Two Numbers %d and %d:\t%d\n", a, b, num1); return 0; } |
Output

If you have any compilation error or doubts in this C program to Add Two Integers using Bitwise Operators, let us know about it in the comment section below.