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


另请阅读

你觉得这篇文章有帮助吗?

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战