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

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

1 comment: