11

#include <iostream>
using namespace std;

int main() {
    int num1, num2, sum;

    cout << "Enter first number: ";
    cin >> num1;

    cout << "Enter second number: ";
    cin >> num2;

    sum = num1 + num2;

    cout << "Sum of " << num1 << " and " << num2 << " is: " << sum << endl;

    return 0;
}

Explanation:

  1. #include <iostream>: Includes the Input/Output Stream Library to perform input and output operations in C++.

  2. using namespace std;: Allows elements of the standard C++ library (e.g., cout, cin) to be used without explicitly qualifying them with 'std::'.

  3. int main() { ... }: The main function where the program execution starts.

  4. int num1, num2, sum;: Declares three integer variables num1, num2, and sum to store user input and the sum of the two numbers.

  5. cout << "Enter first number: ";: Displays a message asking the user to enter the first number.

  6. cin >> num1;: Reads the user input for the first number and stores it in the variable num1.

  7. cout << "Enter second number: ";: Displays a message asking the user to enter the second number.

  8. cin >> num2;: Reads the user input for the second number and stores it in the variable num2.

  9. sum = num1 + num2;: Calculates the sum of num1 and num2 and stores the result in the variable sum.

  10. cout << "Sum of " << num1 << " and " << num2 << " is: " << sum << endl;: Displays the sum of num1 and num2 using cout and concatenates the numbers and the result in the output message.

  11. return 0;: Indicates successful program execution and terminates the main() function.