C++ program to enter two numbers and find their sum
ADVERTISEMENTS
A program to the sum of two integer values
// C++ program to find the sum of two integers
#include <iostream>
using namespace std;
int main() {
int p, q, r;
cout << "Enter two integer values::\n\n";
cin >> p >> q;
// calculating sum
r = p + q;
cout << "Result:: " << p << " + " << q << " = " << r;
return 0;
}
Output:
Enter two integer values::
5
7
Result:: 5 + 7 = 12
A program to the sum of two integer values with minimum variable
// C++ program to find the sum of two integers with minimum variable
#include <iostream>
using namespace std;
int main() {
int p, q;
cout << "Enter two integer values::\n\n";
cin >> p >> q;
cout << "Result:: " << p << " + " << q << " = ";
// calculating sum
p = p + q;
cout << p;
return 0;
}
Output:
Enter two integer values::
5
7
Result:: 5 + 7 = 12
A program to the sum of two float values
// C++ program to find the sum of two float values
#include <iostream>
using namespace std;
int main() {
float p, q;
cout << "Enter two float values::\n\n";
cin >> p >> q;
cout << "Result:: " << p << " + " << q << " = ";
// calculating sum
p = p + q;
cout << p;
return 0;
}
Output:
Enter two float values::
5.23
7.29
Result:: 5.230000 + 7.290000 = 12.52