This C programming example demonstrate the product of two floating type numbers. The product of floating type numbers is achieved using the arithmetic * operator, similar to integer type variables.
C program to multiply two floating point numbers - Source code
float number1, number2, product;
printf("Enter first Number: ");
printf("Enter second Number: ");
//Multiply number1 and number2
product = number1 * number2;
// Displaying result up to 3 decimal places.
printf("Product of entered numbers is:%.3f", product);
Enter first Number: 937.65
Enter second Number: 137.98
Product of entered numbers is:129376.945
Enter first Number: 48.89
Enter second Number: 37.81
Product of entered numbers is:1848.531
1. In this program, user is asked to enter two numbers one by one. These two numbers entered by the user are stored in the floating type variables number1 and number2. This is done using scanf() function.
2. Then, the product of number1 and number2 is evaluated and the result is stored in another floating type variable product.
3. Finally, the value of variable product is displayed on the screen using printf() function.
4. Here note that %.3f is used instead of regular %f format specifier. This is to limit the product result up to three decimal places.