addition

Sum of two integer using without + operator in C

Sum of two integer using without + operator in C

In this article, we will discuss the concept of the Sum of two integer using without + operator in C

In this post, we are going to learn how to  write a program to find the sum of two numbers using without plus operator in C programming language

Code to find the Addition of  two numbers 

Sum of two integer

Add two integer using with – operator

The program allows the user to enter two integers and then calculates the sum of given  numbers using minus operator in C language

Program 1

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

int main()
{
    int num1,num2;
    printf("Enter two number for addition:\n");
    scanf("%d %d",&num1,&num2);
//get input from user for num1 and num1
    int result =num1-(-num2);
//calculate sum of two numbers using minus
printf("Sum of two numbers %d and %d is: %d",num1,num2,result);
//Display result on the screen
getch();
    return 0;
}

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

Enter two number for addition:
1200
2400
Sum of two numbers 1200 and 2400 is: 3600

Add  two integer using for loop with function

The program allows the user to enter two integers and then calculates the sum of given  numbers using for loop with function in C language

Program 2

#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);
//get input from user for n1
    printf("Enter the second number: ");

    scanf("%d",&n2);
//get input from user for n2
     printf("Sum of two  numbers is: %d",add(n1,n2));
//Calling the function to produce output
     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 result

Enter the first number: 250
Enter the second number: 340
Sum of two numbers is: 590

 

Add  two integer using while loop with function

The program allows the user to enter two integers and then calculates the sum of given  numbers using while loop with function in C language

Program 3

#include <stdio.h>
#include <stdlib.h>
int add(int ,int);
int main()
{
    int n1,n2;
    printf("Enter the first number: ");
    scanf("%d",&n1);
//get input from user for n1
    printf("Enter the second number: ");

    scanf("%d",&n2);
//get input from user for n2
     printf("Addition of two  numbers is: %d",add(n1,n2));
//Calling the function to produce output on the screen
     getch();
    return 0;
}

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

}

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

Enter the first number: 135
Enter the second number: 531
Addition of two numbers is: 666

 

Add  two integer  using increment, decrement operator

The program allows the user to enter two integers and then calculates the sum of given  numbers using increment and decrement operator

Program 4

#include <stdio.h> 
#include <stdlib.h>
int add(int ,int);
int main()
{
    int n1,n2;
    printf("Enter the first number: ");
    scanf("%d",&n1);
//get input from user for n1
    printf("Enter the second number: ");
//get input from user for n2

    scanf("%d",&n2);
     printf("adition of two  numbers is: %d",add(n1,n2));
//Calling the function and display result on the screen
     getch();
    return 0;
}

int add(int n1,int n2){//function definition
while(n1>0){
  n2++;
  n1--;
}
while(n1<0){
  n2--;
  n1++;
}
return n2;
}

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

Enter the first number: 455
Enter the second number: 345
Addition of two numbers is: 800

 

Add  two integer using bitwise operator

The program allows the user to enter two integers and then calculates the sum of given  numbers using bitwise operator in C language

Program 5

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

    scanf("%d",&n2);
     printf("Addition of two  numbers is: %d",add(n1,n2));
//Calling the function to produce output
     getch();
    return 0;
}
int add(int num1,int num2){//function definition
while(num2!=0){
    int brw =num1 & num2;
    num1=num1^num2;
    num2=brw<<1;

}
return num1;

}

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

Enter the first number: 123
Enter the second number: 321
Addition of two numbers is: 444

 

Suggested for you

Operator in C language

Data type in C language

variable in C language

if statements in C language

Function in C language

 

 

Similar post

Subtract two numbers in C language

Subtract two numbers using function in C language

Subtract two numbers using recursion in C language

Find addition of two numbers in C language

Find addition of two numbers in C language using pointer

Find addition of two numbers in C language using function

Find addition of two numbers in C using recursion

Find addition of two numbers in C without Arithmetic operator

Find addition of natural numbers in C language

Find addition of natural numbers in C language using recursion

 

Program to sum of two integer using without + operator in Java
Python code to Add two integer using without + operator
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.

Recent Posts

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

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago