6 Different C++ Addition programs to Add Two Numbers

CWC
4 Min Read
6 Different C++ Addition programs to Add Two Numbers

In this article, we will discuss how to add two numbers in C++ Addition programs. In this programming language, we can write the logic and we can even create the program. There are a lot of advantages that we can get when we use C++ programming.

The addition is the fundamental operation in mathematics. The addition is the most important building block for solving many mathematical problems. In this topic, we will learn how to write a C++ Addition program to add two numbers in 6 different ways.

6 Different C++ Addition programs to Add Two Numbers

Example – 1


#include
#include
int main()
{
int a,b;
cout<<"enter the first number";
cin>>a;
cout<<"enter the second number";
cin>>b;
cout<<a+b;< p=""></a+b;<>
getch();
return 0;
}

Example – 2

C++ program to Add Two Numbers

We have been taught to add two numbers from primary level but how to add two numbers on C++. So, in this post, I am going to share the C++ program that will help you to add two numbers. Below is the program that will accept two numbers from the user.

The program will prompt the user for two numbers and the user will enter the numbers and the program will calculate the sum of the two numbers.


#include
int main()
{
cout<<"Enter two numbers: ";
double num1, num2;
cin>>num1>>num2;
cout<
return 0;
}

Example – 3

A program that will accept three numbers from the user.

The program will prompt the user for three numbers and the user will enter the numbers and the program will calculate the sum of the three numbers.


#include
int main()
{
cout<<"Enter three numbers: ";
double num1, num2, num3;
cin>>num1>>num2>>num3;
cout<
return 0;
}

Example – 4

A program that will accept four numbers from the user.

The program will prompt the user for four numbers and the user will enter the numbers and the program will calculate the sum of the four numbers.


#include
int main()
{
cout<<"Enter four numbers: ";
double num1, num2, num3, num4;
cin>>num1>>num2>>num3>>num4;
cout<
return 0;
}

Example – 5


#include
#include
using namespace std;
int main()
{
//Declaring variables
int n1,n2,sum;
//Inputting values
cout<<"Enter first number: ";
cin>>n1;
cout<<"Enter second number: ";
cin>>n2;
//Adding the numbers
sum=n1+n2;
//Outputting the answer
cout<<"Sum is: "<
return 0;
}

Example – 6


#include
using namespace std;
int main()
{
int x=20,y=10;
cout<<"The sum of the two numbers is ";
return 0;
}

Example – 7


#include
int add(int x, int y)
{
return x + y;
}
int main()
{
cout << "Enter x: ";
int x;
cin >> x;
cout << "Enter y: ";
int y;
cin >> y;
cout << "x + y is : " << add(x,y);
return 0;
}

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version