C program to multiply two floating-point numbers; Through this tutorial, we will learn how to multiply two floating-point numbers in the c program.
Algorithm to Multiply Two Floating Point Numbers
Use the following algorithm to write a program to multiply two floating point numbers; as follows:
- Step 1: Start program.
- Step 2: Read two numbers from user and store them into variables.
- Step 3: Multiply two floating point numbers and store result in variable.
- Step 4: Print multiply two floating point numbers.
- Step 5: End program.
C Program to Multiply Two Floating-Point Numbers
#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;
}
The output of the above c program; as follows:
Enter first Number: 3.5 Enter second Number: 5.5 Product of entered numbers is:19.250
C Program to multiply two numbers using function
#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;
}
The output of the above c program; as follows:
Enter first Number: 5.5 Enter second Number: 6.5 Product of entered numbers is:35.750