Simple C++ Program for Beginners
This C++ program takes two numbers as input from the user, adds them, and displays the result.
It demonstrates basic input/output operations and arithmetic calculations in C++.
#include <iostream>
using namespace std;
int main() {
int num1, num2, sum;
cout << "Enter the first number: ";
cin >> num1;
cout << "Enter the second number: ";
cin >> num2;
sum = num1 + num2;
cout << "The sum of " << num1 << " and " << num2 << " is " << sum << "." << endl;
return 0;
}
Steps to Run the Program:
1. Copy the code into a C++ IDE or text editor (e.g., Code::Blocks, VS Code).
2. Compile using a compiler like g++:
g++ program.cpp -o program
3. Run the compiled file:
./program
Sample Output:
Enter the first number: 5
Enter the second number: 10
The sum of 5 and 10 is 15.