🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# C 程序:两个浮点数相乘 > 原文: [https://beginnersbook.com/2017/09/c-program-to-multiply-two-floating-point-numbers/](https://beginnersbook.com/2017/09/c-program-to-multiply-two-floating-point-numbers/) 程序将两个浮点数相乘并将乘积显示为输出。 ## 示例 1:显示两个浮点数乘积的程序 在该程序中,要求用户输入两个浮点数,程序将输入的值存储到变量`num1`和`num2`中。然后程序将输入的数字相乘并将乘积显示为输出。 ```c #include <stdio.h> int main(){ float num1, num2, product; printf("Enter first Number: "); scanf("%f", &num1); printf("Enter second Number: "); scanf("%f", &num2); //Multiply num1 and num2 product = num1 * num2; // Displaying result up to 3 decimal places. printf("Product of entered numbers is:%.3f", product); return 0; } ``` 输出: ```c Enter first Number: 12.761 Enter second Number: 89.23 Product of entered numbers is:1138.664 ``` ## 示例 2:使用函数将两个数相乘的程序 在这个程序中,我们创建了一个用户定义的函数`product()`,它在函数调用期间将我们传递给它的数字相乘。此函数返回这些数字的乘积。要了解该程序,您应该具备以下 [C 编程](https://beginnersbook.com/2014/01/c-tutorial-for-beginners-with-examples/)概念的知识: 1. [C - 函数](https://beginnersbook.com/2014/01/c-functions-examples/) 2. [C - 按值调用函数](https://beginnersbook.com/2014/01/c-function-call-by-value-example/) ```c #include <stdio.h> /* Creating a user defined function product that * multiplies the numbers that are passed as an argument * to this function. It returns the product of these numbers */ float product(float a, float b){ return a*b; } int main() { float num1, num2, prod; printf("Enter first Number: "); scanf("%f", &num1); printf("Enter second Number: "); scanf("%f", &num2); // Calling product function prod = product(num1, num2); // Displaying result up to 3 decimal places. printf("Product of entered numbers is:%.3f", prod); return 0; } ``` 输出: ```c Enter first Number: 12.761 Enter second Number: 89.23 Product of entered numbers is:1138.664 ``` 查看这些相关的 [C 程序](https://beginnersbook.com/2015/02/simple-c-programs/): 1. [C 程序:相加两个数字](https://beginnersbook.com/2017/09/c-program-to-add-two-numbers/) 2. [C 程序:打印用户输入的整数](https://beginnersbook.com/2017/09/c-program-to-print-an-integer-entered-by-a-user/) 3. [C 中的`Hello World`程序](https://beginnersbook.com/2017/09/c-hello-world-program/) 4. [C 程序:查找给定范围内的回文数](https://beginnersbook.com/2015/02/c-program-to-find-palindrome-numbers-in-a-given-range/) 5. [C 程序:将小写字符串转换为大写](https://beginnersbook.com/2015/02/c-program-to-convert-lowercase-string-to-uppercase-string/)