C++ Programs to find Mathematical Operations - SUM(Addition)
Program to Print SUM Of Two Numbers in C++ : -
_____________________________________
Program to find sum of two numbers (both the integer and float values): -
Program 1: -
![]() |
| Input program to find addition of two numbers. |
#include <iostream>
using namespace std;
int main() {
cout << "sum of two numbers = ";
cout << 10 +20;
}
Output: -
![]() |
| Output of Program1. |
sum of two numbers = 30
Program 2: -
![]() |
| Input program |
#include <iostream>
using namespace std;
int main() {
cout << "sum of two numbers = ";
cout << 10.6+3.6;
}
Output: -
![]() |
| Output. |
sum of two numbers = 14.2
- The above code is applicable to find the addition of both the integer and float values.
Program to find sum of two integer numbers: -
Program: -
![]() |
| Input |
#include <iostream>
using namespace std;
int main() {
int x = 5;
int y = 6;
int sum = x + y;
cout << sum;
return0;
}
Output: -
11
![]() |
| Output. |
Program to find the sum of two float values: -
Program: -
![]() |
| input program to find sum of two float values. |
using namespace std;
int main() {
float x = 5.5;
float y = 12.2;
float sum = x + y;
cout << "the sum of two float values = " << sum;
return0;
}
Output: -
the sum of two float values = 17.7
![]() |
| output |
__________________________________________________________________________
Program to find sum of any two given numbers: -
Program: -
![]() |
| input |
#include <iostream>
using namespace std;
int main() {
int num1, num2;
cout << "Enter two integer values = ";
cin >> num1 >> num2;
cout <<"the sum of two given integer values is : " << num1 + num2;
}
Output: -
After running the above code the console display's: -
- Enter two integer values =
Now enter any two integer values: -
- Enter two integer values = 29 92
- Enter two integer values = 29 92
- the sum of two given integer values is : 121
![]() |
| output 1 |
![]() |
| output 2 |
As we have declared in the program that the num1 & num2 are integer data type, the above program is only valid for the addition of integer values.
If in case you want to add two float values. Use the above code by changing the int to float in the declaration of Data type, as shown in below code.
Code: -
#include <iostream>
using namespace std;
int main() {
float num1, num2;
cout << "Enter two float values = ";
cin >> num1 >> num2;
cout <<"the sum of two given float values is : " << num1 + num2;
}
"THANK YOU!"











Comments
Post a Comment
Leave your Quires here!