addition

C program to find sum of two numbers without using arithmetic operators

C program to find the sum of two numbers without using arithmetic operators

In this tutorial, we will discuss the concept of C program to find the sum of two numbers without using arithmetic operators

In this post, we will learn how to make the addition of two number using without arithmetic operator in C programming language

 

Addition

C program to find the sum of two numbers

Using for loop – Program 1

This program allows finding the addition of two numbers entered by the user – using for loop without arithmetic operator

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1,num2,i;  //Variable declaration
    printf("Enter the first number: ");
    scanf("%d",&num1); 
    printf("Enter the second number: ");
    scanf("%d",&num2);
    for(i=0; i<num2; i++){
   num1++;
    }
printf("Sum of two numbers : %d ",num1);
getch();
    return 0;
}

When the above code is executed, it produces the following results

Enter the first number: 26
Enter the second number: 84
Sum of two numbers : 110

 

Methods

  • User inputs the first number using printf() function
  • Store the number in variable num1 using scanf() function
  • User inputs the second number using printf() function
  • Store  the number in variable num2 using scanf() function
  • for loop” used to calculate the addition of two numbers.
  • Display the sum of the numbers on the screen.

 

Using while loop – Program 2

This program allows finding the addition of two numbers entered by the user using while loop without arithmetic operator

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1,num2,i;  //Variable declaration
    printf("Enter the first number: ");
    scanf("%d",&num1);
    printf("Enter the second number: ");
    scanf("%d",&num2);
    while(num2 != 0){
int num3=(num1 & num2);
num1=num1^num2;
num2=num3<<1;
}
printf("Sum of two numbers is:%d ",num1);
getch();
    return 0;
}

When the above code is executed, it produces the following results

Enter the first number: 125
Enter the second number: 65
Sum of two numbers : 190

Methods

  • User input the first number using printf() function
  • Store  the number in variable num1 using scanf() function
  • User inputs the second number using printf() function
  • Store the number in variable num2 using scanf() function
  • while loop is used to calculate the addition of two numbers.
  • Display the sum of the number

 

Using for loop – inside the function – program 3

This program allows finding the addition of two numbers entered by the user using for loop without arithmetic operator

#include <stdio.h>
#include <stdlib.h>
int add(int ,int);  //function protottype or diclaration
int main()
{
    int n1,n2;  //Variable declaration
    printf("Enter the first number: ");
    scanf("%d",&n1);
    printf("Enter the second number: ");

    scanf("%d",&n2);
     printf("Sum of two  numbers is: %d",add(n1,n2)); //function call
     getch();
    return 0;
}

int add(int num1, int num2){  //function definition
int i;
for(i=0; i<num2; i++){
   num1++;
}
return num1;

}

 

When the above code is executed, it produces the following results

Enter the first number: 123
Enter the second number: 234
Sum of two numbers : 357

Method

  • User inputs the first number using printf() function
  • Store the number in variable num1 using scanf() function
  • User inputs the second number using printf() function
  • Store  the number in variable num2 using scanf() function
  • Create a function with  “for loop” to find the sum of two numbers.
  • Call the function inside the main method.
  • Display the sum of the number on the screen

 

 

Using while loop – inside the function – program 4

This program allows finding the addition of two numbers entered by the user using while loop without arithmetic operator

#include <stdio.h>
#include <stdlib.h>
int add(int ,int);  //function prototype
int main()
{
    int n1,n2;  //Variable declaration
    printf("Enter the first number: ");
    scanf("%d",&n1);
    printf("Enter the second number: ");

    scanf("%d",&n2);
     printf("Sum of two  numbers is: %d",add(n1,n2)); //function call
     getch();
    return 0;
}

int add(int num1, int num2){ //function definition
int i;
while(num2 != 0){
int num3=(num1 & num2);
num1=num1^num2;
num2=num3<<1;
}
return num1;

}

 

When the above code is executed, it produces the following results

Enter the first number: 300
Enter the second number: 250
Sum of two numbers : 550

Method

  • User inputs the first number using printf() function
  • Store  the number in variable num1 using scanf() function
  • User inputs the second number using printf() function
  • Store  the number in the variable num2 using scanf() function
  • Create a function with  “while loop” to find the sum of two numbers.
  • call the function inside the main method
  • Display the sum of the number on the screen

 

Similar post

C++ program to find the sum  of two numbers without using arithmetic operators

Java program to find the sum of two numbers without using arithmetic operators

Python program to find the sum of two numbers without using arithmetic operators

Java program to sum of two numbers

C program to sum of two numbers

C++ program to sum of two numbers

Python program to sum of two numbers

C++ program to find the sum  of two numbers  using recursion

C program to find the sum  of two numbers  using recursion

Java program to find the sum  of two numbers  using recursion

Python program to find the sum  of two numbers  using recursion

 

 

Suggested for you

For loop in C language

While loop in C language

Function in C language

User-defined function in C language

Input-output function in C language

The operator in C language

 

C++ program to find product of two numbers using pointer
C++ program to add two numbers without using arithmetic operators
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

View Comments

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

20 hours ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago