C++ program to add two numbers
C++ program to add two numbers.
C++ programming code
----------------------------------------------------------------------------
#include <iostream>
using namespace std;
int main()
{
int n1, n2, result;
cout << "Enter two integers to add : \n";
cin >> n1 >> n2;
{
int n1, n2, result;
cout << "Enter two integers to add : \n";
cin >> n1 >> n2;
result = n1 + n2;
cout <<"Sum of the numbers: " << result << endl;
return 0;
}
cout <<"Sum of the numbers: " << result << endl;
return 0;
}
C++ addition program using class
----------------------------------------------------------------------------
#include <iostream>
using namespace std;
class Mathematics {
int n1, n2;
int n1, n2;
public:
void input() {
cout << "Input two integers\n";
cin >> n1 >> n2;
}
void input() {
cout << "Input two integers\n";
cin >> n1 >> n2;
}
void add() {
cout << "Result: " << n1 + n2;
}
cout << "Result: " << n1 + n2;
}
};
int main()
{
Mathematics m; // Creating an object of the class
{
Mathematics m; // Creating an object of the class
m.input(); // calling input function of the class
m.add(); // calling add function of the class
m.add(); // calling add function of the class
return 0;
}
}
0 Comments
you can ask question related to this post