合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# C 程序:将两个浮点数相乘 > 原文: [https://www.programiz.com/c-programming/examples/product-numbers](https://www.programiz.com/c-programming/examples/product-numbers) #### 在此示例中,计算用户输入的两个浮点数的乘积并将其打印在屏幕上。 要理解此示例,您应该了解以下 [C 编程](/c-programming "C tutorial")主题: * [C 变量,常量和字面值](/c-programming/c-variables-constants) * [C 数据类型](/c-programming/c-data-types) * [C 输入输出(I/O)](/c-programming/c-input-output) * [C 编程运算符](/c-programming/c-operators) * * * ## 将两个数字相乘的程序 ```c #include <stdio.h> int main() { double a, b, product; printf("Enter two numbers: "); scanf("%lf %lf", &a, &b); // Calculating product product = a * b; // Result up to 2 decimal point is displayed using %.2lf printf("Product = %.2lf", product); return 0; } ``` **输出** ```c Enter two numbers: 2.4 1.12 Product = 2.69 ``` * * * 在该程序中,要求用户输入两个数字,分别存储在变量`a`和`b`中。 ```c printf("Enter two numbers: "); scanf("%lf %lf", &a, &b); ``` 然后,求值`a`和`b`的乘积,并将结果存储在`product`中。 ```c product = a * b; ``` 最后,使用`printf()`在屏幕上显示`product`。 ```c printf("Product = %.2lf", product); ``` 注意,结果使用`%.2lf`转换字符四舍五入到小数点后第二位。