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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago