Multiplying two numbers is a simple task in C, but in this article, we are going to perform the multiplication of two floating point numbers. Floating point numbers are those numbers that represent real numbers with fractional components.
Table of Contents
C Program To Multiply Floating Point Numbers
This is a simple C Program that illustrates how to multiply two floating point numbers.
#include <stdio.h>
void main()
{
float num1, num2, result;
printf("Enter the first floating point number");
scanf("%f", &num1);
printf("Enter the second floating point number");
scanf("%f", &num2);
result = num1 * num2;
printf("Product of %f & %f = %f", num1, num2, result);
}
Output
Explaination of Above C Program
#include <stdio.h>
is a preprocessor that includes a standard input/output library required for input and output operations.- Declare three float variables num1, num2, and result.
- Ask the user to enter two floating point numbers using printf() and scanf().
- Perform the multiplication of two floating point numbers by using the ‘*’ operator and store the product in the result variable.
- At the end print the result by using printf().
Note
- Use “%f” format specifier with printf and scanf function for taking input of float number with scanf() and for printing float number with printf().
2 thoughts on “Multipling Floating Point Numbers in C”