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.
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.
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;


using namespace std;                    
int main()                                    
long a,b,c;                                 

cout<<"enter the two number :"<<endl;


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

cout<<"enter the two nuber :"<<endl;


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

cout<<"enter the two nuber :"<<endl;


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

cout<<"enter the two nuber :"<<endl;


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

cout<<"enter the two nuber :"<<endl;


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

cout<<"enter the two nuber :"<<endl;


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


C++ Program To Find Addition, Subtraction, Multiply, Divide And Average

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

1 comment: