Multiplying Numbers In C++

Exercise:

Write a C++ program to multiply two entered numbers.

Click Here to View the Solution:
#include <iostream>
using namespace std;
int main()
{
    double Num1, Num2, ans;
    cout << "Please insert two numbers for multiplication:\n";
    cin >> Num1 >> Num2;
    ans = Num1 * Num2;  
    cout << Num1 << " x "<< Num2 <<" = " << ans;    
    return 0;
}
Click Here to View the Output:
Please insert two numbers for multiplication:
4.86
22.451
4.86 x 22.451 = 109.112
Click Here to View the Explanation:
  • Two numbers are requested from the user for the execution of the code to begin.
  • 3 double type variables are declared: Num1, Num2, and ans. This allows the user to input decimal numbers.
  • When the numbers are entered, they are multiplied and saved as a new variable ans.
  • This variable is printed on the screen.

%d bloggers like this: