C++ Program to Multiply two Numbers

Write a C++ program that takes two integers as input from the user and calculates their product.

Input and Output Examples

  1. Input: 5, 10 Output: The product is 50.
  2. Input: -3, 7 Output: The product is -21.

Algorithm

  1. Prompt the user to input two integers.
  2. Read the input values.
  3. Multiply the two numbers.
  4. Display the result to the user.

Below is the C++ code that multiplies two numbers:

cpp
#include <iostream>
using namespace std;

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

    // Step 1: Prompt the user to input two integers
    cout << "Enter two numbers: ";

    // Step 2: Read the input values
    cin >> num1 >> num2;

    // Step 3: Multiply the two numbers
    product = num1 * num2;

    // Step 4: Display the product to the user
    cout << "The product is " << product << ".";

    return 0; // Successful completion of the program
}

Testing with Different Input Values

The program can handle any integer values, including negative numbers and zeros, producing accurate results in all cases.

Input and Output Examples for Modified Program:

  1. Input: -4, -8 Output: The product is 32.
  2. Input: 0, 100 Output: The product is 0.

Programming

5788

806

Related Articles