In this tutorial you will learn about the C++ Program to Perform Addition, Subtraction, Multiplication and Division and its application with practical example.
C++ Program to Perform Addition, Subtraction, Multiplication, and Division
In this tutorial, we will learn to create a C++ program. After that will perform Addition, Subtraction, Multiplication, and Division in C++ programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C++ programming topics:
- Operators in C++ Programming.
- Basic Input and Output function in C++ Programming.
- Basic C++ Programming.
Program for performing the Addition, Subtraction, Multiplication, and Division:-
In today’s tutorial, we will create a program. That will do the Addition, Subtraction, Multiplication, and Division operations with the help of Arithmetic operators in C++ programming.
Algorithm for Addition, Subtraction, Multiplication, and Division:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
1. Declaring the variables for the program. 2. Taking the input numbers from the user in number format. 3. Adding the numbers and storing it in a variable. 4. Subtracting the numbers and storing it in a variable. 5. Multiplying the numbers and storing it in a variable. 6. Dividing the numbers and storing it in a variable. 7. Printing the Outputs. 8. End program. |
Program for Addition, Subtraction, Multiplication, and Division:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
/* C++ Program to Perform Addition, Subtraction, Multiplication, and Division of Two Numbers */ #include <iostream> using namespace std; int main() { //Declaring the variables for the program int fno, sno, multiplyy,addd,subb,dividee; //Taking input numbers from the user for multiplicaiton of the two values. cout << "Enter two numbers: "; cin >> fno >> sno; // sum of two numbers in stored in variable addd addd = fno + sno; // subtracton of two numbers in stored in variable subb subb = fno - sno; // multiplicaiton of two numbers in stored in variable multiplyy multiplyy = fno * sno; // division of two numbers in stored in variable dividee dividee = fno / sno; // Prints addition of two numbers cout << "addition of two numbers " << fno << " + " << sno << " = " << addd <<endl; // Prints subtraction of two numbers cout << "subtraction of two numbers " << fno << " - " << sno << " = " << subb <<endl; // Prints multiplication of two numbers cout << "multiplication of two numbers " << fno << " * " << sno << " = " << multiplyy <<endl; // Prints division of two numbers cout << "division of two numbers " << fno << " / " << sno << " = " << dividee <<endl; return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- fno = it will hold the input number value from the user.
- sno = it will hold the input number value from the user.
- addd = it will hold the added value of the numbers.
- subb= it will hold the subtraction value of the numbers.
Taking Input numbers from the user.
Perform Addition, Subtraction, Multiplication, and Division of two numbers.
Printing the output.