In this example, you will learn how to multiply two floating-point numbers by taking input from the user and display the results on the screen.
You can learn more C Programming concepts here.
C Program to Multiply two floating-point numbers
Enter two numbers: 5.5 1.3 Product = 7.150
In this example, the user is asked to enter two floating-point numbers. The two numbers entered by the user will be stored in numberOne and numberTwo respectively.
printf("Enter two numbers: "); scanf("%lf %lf", &numberOne, &numberTwo);
Then the numberOne and numberTwo are multiplied using the * operator and the result is stored in product.
product = numberOne * numberTwo;
product variable is of type double, which is capable of storing value till 15 decimals. Here in this example, we can display the output restricting to 3 decimals using %.3lf (.3 represents 3 decimals after the point).
printf("Product = %.3lf", product);