addition

C++ code to Add two integer using without + operator

C++ code to Add two integer using without + operator

In this article, we will discuss the concept of the C++ code to Add two integer using without + operator

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

Java code to Add two integer

Code to find the sum of  two numbers 

Sum of 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 <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int num1,num2;
    cout<<"Enter two number for addition:\n";
    cin>>num1>>num2;
//get input from the user for num1 and num2
    int result =num1-(-num2);
//Calculate addition using - operator
cout<<"Sum of two numbers "<<num1<<" and "<<num2<<" is "<<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
2222
111
Sum of two numbers 2222 and 111 is 2333

 

Sum of two integer using for loop

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

Program 2

#include <iostream>
#include <conio.h>

using namespace std;

int add(int ,int);//function prototype
int main()
{
    int n1,n2;
    cout<<"Enter the first number: ";
    cin>>n1;
//get input from the user for n1
    cout<<"Enter the second number: ";
    cin>>n2;
//get input from the user for n2
     cout<<"Sum of two  numbers is: "<<add(n1,n2);
//Calling the function and display result on the screen
     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: 321
Enter the first number:432
Sum of two numbers is: 753

 

Sum of two integer using while loop

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

Program 3

#include <iostream>
#include <conio.h>
using namespace std;

int add(int ,int);//function prototype
int main()
{
    int n1,n2;
    cout<<"Enter the first number: ";
    cin>>n1;
//get input from the user for n1
   cout<<"Enter the second number: ";
    cin>>n2;
//get input from the user for n2
    cout<<"Sum of two  numbers is:"<<add(n1,n2);
//Calling the function and display result 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: 456
Enter the first number: 678
Sum of two numbers is: 1134

 

Sum of 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,decrement operator in C++ language

Program 4

#include <iostream>
#include <conio.h>
using namespace std;

int add(int ,int);//function prototype
int main()
{
    int n1,n2;
    cout<<"Enter the first number: ";
    cin>>n1;
//get input from the user for n1
    cout<<"Enter the second number: ";
    cin>>n2;
//get input from the user for n2
     cout<<"Sum of two  numbers is: "<<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: 2345
Enter the first number: 3456
Sum of two numbers is: 5801

 

Suggested for you

Operator in C++ language

Data type in C++ language

Variable in C++ language

if statements 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 sum of two numbers in C++

Find sum of two numbers in C++ using recursion

Find sum of two numbers in C++ without Arithmetic operator

Find sum of natural numbers in C++ language

Find sum of natural numbers in C++ language using recursion

Python code to Add two integer using without + operator
Java code to divide two numbers using method
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