C++ Online Compiler
Example: Sum and Product of Two Numbers in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Sum and Product of Two Numbers #include <iostream> // Required for input/output operations int main() { // Step 1: Declare two integer variables to store the input numbers. int num1, num2; // Step 2: Prompt the user to enter the first number. std::cout << "Enter the first number: "; // Step 3: Read the first number from the user and store it in num1. std::cin >> num1; // Step 4: Prompt the user to enter the second number. std::cout << "Enter the second number: "; // Step 5: Read the second number from the user and store it in num2. std::cin >> num2; // Step 6: Calculate the sum of the two numbers. int sum = num1 + num2; // Step 7: Calculate the product of the two numbers. int product = num1 * num2; // Step 8: Display the calculated sum. std::cout << "Sum: " << sum << std::endl; // Step 9: Display the calculated product. std::cout << "Product: " << product << std::endl; // Step 10: Indicate successful program execution. return 0; }
Output
Clear
ADVERTISEMENTS