Home / C / C program for adding two numbers without using Arithmetic Operator

C program for adding two numbers without using Arithmetic Operator

 C program to add two numbers without using Arithmetic Operator: There are many ways to add two numbers or sum up two numbers without using a arithmetic Operator. The methods are listed below: 

 

Method #1

Method #1: Adding two number using subtraction :  This ones a impressive method. LOL !

#include "stdio.h"

int main() {
   int num1 = 10, num2 = 5;

   num1 = num1 - (-num2);
   printf("Sum is : %d",num1);

   return (0);
}

Method #2

#include <stdio.h>

int sum(int, int);
int main() {
   int num1, num2;

   printf("\nEnter the two Numbers : ");
   scanf("%d %d", &num1, &num2); //Enter two numbers 

   printf("\nSum of two num is : %d", sum(num1, num2)); //user defined function is now called
   return (0);
}

int add(int num1, int num2) // the two values are now passed in to this function whose output will be sent back to the method called
{
   if (!num1)
      return num2;
   else
      return sum((num1 & num2) << 1, num1 ^ num2);
}

 

Check Also

Restrict Mouse Pointer Position C Graphics Program

This C Program will restrict the Mouse Pointer location or to a particular position or x,y ...