两个数字相乘的 C++程序

在这个程序中,要求用户输入两个数字(浮点数)。然后,将这两个数字的乘积存储在一个变量中并显示在屏幕上。

两个数字相乘的 C++程序

#include <iostream>
using namespace std;

int main() {
  double num1, num2, product;
  cout << "Enter two numbers: ";

  // stores two floating point numbers in num1 and num2 respectively
  cin >> num1 >> num2;

  // performs multiplication and stores the result in product variable
  product = num1 * num2;

  cout << "Product = " << product;

  return 0;
}

输出

Enter two numbers: 3.4
5.5
Product = 18.7

在这个程序中,要求用户输入两个数字。用户输入的这两个数字 分别存储在变量 num1num2 中。

然后, num1num2 相乘并将结果存储在变量 product 中.

最后, 在屏幕上输出 product