Table of Contents
How to write a C Program to multiply two floating point numbers
In this article, we will discuss the concept of How to write a C Program to multiply two floating point numbers
In this post, we are going to learn how to write a program to calculate product of two floating point numbers using different methods in C programming language.
Code to calculate product of two floats
Code to calculate product of two floating point numbers
In this program, we will calculate product of two floating point numbers using variable declaration and initialization in C language
Program 1
#include <stdio.h> #include <stdlib.h> int main() { printf("calculate Product of two floating point value\n"); float first_No=12.5,last_No=5.5,product; //declaring and initializing variables product=first_No * last_No; //multiply given two numbers and assgn the result in variable product printf("Product is : = %.3f",product); //display result up to 3 decimal places getch(); return 0; }
When the above code is executed, it produces the following result
calculate Product of two floating point value Product is: = 68.750
Code to calculate product of two floating point numbers – using user input
In this program, we will calculate product of two floating point numbers using input from the user in C language
Program 2
#include <stdio.h> #include <stdlib.h> int main() { printf("calculate Product of two floating point value\n"); float first_No,last_No,product; //declaring three variables printf("Enter first number: "); //request input from the user scanf("%f",&first_No); //store the floating point value in variable first_No printf("Enter last number: "); //request input from the user scanf("%f",&last_No); //store the floating point value in variable last_No product=first_No * last_No; //multiply given two numbers and store the result in variable product printf("Product is : = %.3f",product); //display result up to 3 decimal places getch(); return 0; }
When the above code is executed, it produces the following result
calculate Product of two floating point value Enter first number: 10.6 Enter last number: 5.1 Product is: = 53.550
Code to calculate product of two floating point numbers using function
In this program, we will calculate product of two floating point numbers using function in C language
Program 3
#include <stdio.h> #include <stdlib.h> float mulNum(float,float); int main() { printf("find Product of floating point value\n"); float f_No=50.5,s_No=25.6,product; //declaring and initializing variables product=mulNum(f_No,s_No); //calling the function and assigning the output to product variable printf("Product is : = %.3f",product); //display result up to 3 decimal places getch(); return 0; } float mulNum(float a, float b){//function definition float result=a * b; //multiply two numbers and store the output in variable result return result; //return the result to main method }
When the above code is executed, it produces the following result
Find Product of two floating point value Product is: = 1292.800
Code to calculate product of two floating point numbers using function with user input
In this program, we will calculate product of two floating point numbers using function with user input in C language
Program 4
#include <stdio.h> #include <stdlib.h> float mulNum(float,float); int main() { printf("find Product of floating point value\n"); float f_No,s_No,product; printf("Enter first number: "); //ask input from the user scanf("%f",&f_No); //storing the input value in variable f_No printf("Enter second number: "); //ask input from the user scanf("%f",&s_No); //storing the input value in variable s_No product=mulNum(f_No,s_No); //calling the function and assigning the output to product variable printf("Product is : = %.3f",product); //display result up to 3 decimal places getch(); return 0; } float mulNum(float a, float b){//function definition float result=a * b; //multiply two numbers and store the output in variable result return result; //return the result to main method }
When the above code is executed, it produces the following result
Find Product of two floating point value Enter first number: 10.6 Enter last number: 5.1 Product is: = 53.550
Suggested for you
Similar post
Java code to product of two numbers
C code to product of two numbers
C++ code to product of two numbers
Python code to product of two numbers
Java code to Calculate product of two floating point numbers
C code to Calculate product of two floating point numbers
C++ code to Calculate product of two floating point numbers
Python code to Calculate product of two floating point numbers