###
C++ Program For Addition, Subtraction, Multiply, Divide And Average

**Problem:- **C++ Program To Find Addition, Subtraction, Multiply, Divide And Average.

**Logic:- **For this type of question, we all know that addition, subtraction, multiply, divide, and average. For addition, we use a plus(+) operator, for subtraction we use minus(-) operator, for multiple we use an asterisk(*), for divide or division we use, the division operator or asterisk(*) and for average first, we add all number then divide the total sum by counting number.

**1. Addition:-**

Sum = number X + number Y......................number n.

for addition at-least, 2 number required means if you want a sum than two number required. Example 5+15=20, here we know that in the programming language we need to store a number in variables so we should initialize some variable.
**Explanation:**
int number1,number2.
int sum_of_number1_and_number2.
so first number 5 stored in number1, and 15 stored in number2. Now, what is a use of sum_of_number1_and_number2 ?.
5 and 15 are already stored in number1 and number2 than for storing the sum value of 5+15 we initialize third variable sum_of_number1_and_number2.

sum_of_number1_and_number2 = number1 + number2;

sum_of_number1_and_number2 = 5 + 15;

Values of sum_of_number1_and_number2 = 20;
and in the last, we print the sum value. I hope now I am clear about variables and logic.
same process repeat for subtraction, multiply and divide. But for average there is little bit change

**2. Average:-**

For average process is similar but here you need to count a number. cause after adding you need to divide a number. For that, you can either use the third variable or you can do this by using the same variable.
**Explanation:**
sum_of_number1_and_number2 = number1 + number2;
now we know that there is two number then in the last we divide a sum_of_number1_and_number2 by two.
Average = sum_of_number1_and_number2 / 2;
Average = 20 / 2;
Average = 10;

**Solution:-**

#include<iostream>
using namespace std;
int main()
{
long a,b,c;
cout<<"enter the two number :"<<endl;
cin>>a>>b;

c=a+b;
cout<<"sum is = "<<c<<endl;
cout<<"enter the two nuber :"<<endl;
cin>>a>>b;

c=a-b;

cout<<"sub is = "<<c<<endl;

cout<<"enter the two nuber :"<<endl;
cin>>a>>b;

c=a*b;

cout<<"mul is = "<<c<<endl;

cout<<"enter the two nuber :"<<endl;
cin>>a>>b;
c=a/b;

cout<<"dev is = "<<c<<endl;
cout<<"enter the two nuber :"<<endl;
cin>>a>>b;

c=a%b;

cout<<"modulus is = "<<c<<endl;

cout<<"enter the two nuber :"<<endl;
cin>>a>>b;

c=(a+b)/2;

cout<<"avg is = "<<c<<endl;
return 0;
}

**Output:-**

**Share This Article With Your Friends**

Recommended Posts For You

#### Don't Miss Another Article

Join over 5,000 people who get FREE and fresh content from this Blog. We Respect Privacy, You're Safe! No Spam!

##### Ghanendra Yadav

I Am Ghanendra Yadav Owner Of This Website. I Love Programming, Web Developing, Logo Making, Banner And Website designing. Currently I Am Studying In **NIT Warangal** And Also Working With **WSDC**( As Web Application Developer ) **In NIT Warangal** For Any Query Mail Me I Will Answer Within 24 Hours Email:- **yghanendra@student.nitw.ac.in**

nice job bro

ReplyDelete