At the last add two numbers and perform the addition and store both numbers Sum in the third variable(Add_Two_Numbers).
C++ Program to Add Two Numbers
#include <iostream>
using namespace std;
int main()
{
/*C++ Program to Add Two Numbers*/
int Number_First, Second_Number, Add_Two_Numbers;
cout << "Enter Two Numbers to Add: ";
cin >> Number_First >> Second_Number;
// Addition of two numbers in stored in the Third variable Add_Two_Number.
Add_Two_Numbers = Number_First + Second_Number;
// Prints the Addition of Two Number(Add_Two_Number)
cout << Number_First << " + " << Second_Number << " = " << Add_Two_Numbers;
return 0;
}
C++ Program to Add Two Numbers Without Using Third Variable
#include <iostream>
using namespace std;
int main()
{
/*C++ Program to Add Two Numbers Without using the Third Variable */
int Number_First, Second_Number;
cout << "Enter Two Numbers to Add: ";
cin >> Number_First >> Second_Number;
// Addition of two numbers in stored in the First variable Number_First.
Number_First = Number_First + Second_Number;
// Prints the Addition of Two Number(Number_First)
cout << Number_First;
return 0;
}
The Output of C++ Program to Add Two Numbers
5 Steps Explanation Add Two Numbers
- First Initialise the 3 variables in the C++ Programs.
- Ask the user to enter the 2 numbers, Which the user wants to Add or wants to perform in the two-number addition.
- Proform the addition of two Numbers
- Store the addition result in the third variable.
- Print the output of the Third Variable value.
0 Comments: