给定两个浮点数A和B。任务是编写一个程序来查找这两个数的乘积。
例子:
Input: A = 2.12, B = 3.88
Output: 8.225600
Input: A = 3.78, B = 6.32
Output: 23.889601
在下面的程序中,将两个浮点数相乘,首先要求用户输入两个浮点数,然后使用scanf()函数对输入进行扫描并将其存储在变量中和 。然后,变量和使用算术运算运算符相乘并且产品存储在变量product中。
下面是将两个浮点数相乘的C程序:
// C program to multiply two floating point numbers
#include
int main()
{
float A, B, product = 0.0f;
// Ask user to enter the two numbers
printf("Enter two floating numbers A and B : \n");
// Read two numbers from the user || A = 2.12, B = 3.88
scanf("%f%f", &A, &B);
// Calclulate the multiplication of A and B
// using '*' operator
product = A * B;
// Print the product
printf("Product of A and B is: %f", product);
return 0;
}
输出:
Enter two floating numbers A and B : 2.12 3.88
Product of A and B is: 8.225600
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。