两个数字相乘的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 显示在屏幕上。