Skip to content

Latest commit

 

History

History
45 lines (29 loc) · 1.24 KB

File metadata and controls

45 lines (29 loc) · 1.24 KB

C++ 程序:将两个数相乘

原文: https://www.programiz.com/cpp-programming/examples/product-numbers

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


C++ 程序:将两个数字相乘

#include <iostream>
using namespace std;

int main()
{
    double firstNumber, secondNumber, productOfTwoNumbers;
    cout << "Enter two numbers: ";

    // Stores two floating point numbers in variable firstNumber and secondNumber respectively
    cin >> firstNumber >> secondNumber;

    // Performs multiplication and stores the result in variable productOfTwoNumbers
    productOfTwoNumbers = firstNumber * secondNumber;  

    cout << "Product = " << productOfTwoNumbers;    

    return 0;
}

输出

Enter two numbers: 3.4
5.5
Product = 18.7

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

然后,求值firstNumbersecondNumber的乘积,并将结果存储在变量productOfTwoNumbers中。

最后,在屏幕上显示productOfTwoNumbers