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
在此程序中,用户被要求输入两个数字。用户输入的这两个数字分别存储在变量 num1 和 num2 中。
然后,计算 num1 和 num2 的乘积,并将结果存储在变量 product 中。
最后,在屏幕上显示 product。
另请阅读