How to Add two numbers without using arithmetic Operators in C Programming ?

January 10, 2025 2 Comments » Hits : 268





Way 1 : Using Recursive Function

#include<stdio.h>
#include<conio.h>
int add(int,int);
void main()
{
int a,b;
clrscr();
printf("Enter the two Numbers: ");
scanf("%d%d",&a,&b);
printf("Addition of two num. is : %d",add(a,b));
getch();
}
//-----------------------------------------------
int add(int a, int b)
{
if (!a)
   return b;
else
   return add((a & b) << 1, a ^ b);
}

Way 2 : Using While Loop

#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,b=5,i;
clrscr();
while(b>0)
  {
  a++;
  b--;
  }
printf("%d",a);
getch();
}

Way 3 : Using While Loop

#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,b=5;
while(b--)
   a++;
printf("Sum is : %d" a);
}

Way 4 : Using For Loop

#include<stdio.h>
#include<conio.h>
int sum(int,int);
void main()
{
int a,b;
clrscr();
printf("Enter the two Numbers: ");
scanf("%d%d",&a,&b);
printf("Addition of two num. is : %d",add(a,b));
getch();
}
int add(int num1,int num2)
{
int i;
for(i=0;i< num2;i++)
   num1++;
return num1;
}

Way 5 : Using Subtraction

#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,b=5;
a = a-(-b);
printf("Sum is : %d" a);
}

Note : This Example have Arithmetic Operator [-] but this example is for “Adding two numbers without using + Operator

Incoming search terms:

  • sriraj

    HERE IS THE PERFECT PROGRAM
    int add(int,int);
    void main()
    {
    int a,b;
    clrscr();
    printf("Enter 2 non");
    scanf("%d%d",&a,&b);
    printf("Add=%d",add(a,b));
    getch();
    }
    int add(int a,int b)
    {
    if(b==0)
    return 1;
    else
    return(a+add(1,b-1));
    }

  • Gertrude Tabisula

    I do not even understand how I stopped up here, but I assumed this post was once good. I don’t understand who you might be however definitely you are going to a famous blogger in case you are not already Cheers!