**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:-**

nice job bro

ReplyDelete