原文: https://www.programiz.com/c-programming/examples/product-numbers
要理解此示例,您应该了解以下 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;
} 输出
Enter two numbers: 2.4
1.12
Product = 2.69 在该程序中,要求用户输入两个数字,分别存储在变量a和b中。
printf("Enter two numbers: ");
scanf("%lf %lf", &a, &b); 然后,求值a和b的乘积,并将结果存储在product中。
product = a * b; 最后,使用printf()在屏幕上显示product。
printf("Product = %.2lf", product); 注意,结果使用%.2lf转换字符四舍五入到小数点后第二位。