Table of Contents
C++ Program to multiply two floating point numbers
In this article, we will discuss the concept of 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++ program.
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 <iostream> #include <conio.h> using namespace std; int main() { cout<<"calculate Product of two floating point numbers\n"; float first_No=10.25,last_No=5.5,product; //declaring and initializing variables product=first_No * last_No; //multiply given two numbers and store the result in variable product cout<<"Product is : "<<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 numbers Product is : 56.375
Code to calculate product of two floating point numbers – user input
In this program, we will calculate product of two floating point numbers using takes input from the user in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { cout<<"calculate Product of two floating point value\n"; float first_No,last_No,product; //declaring three variables cout<<"Enter first number: "; //request input from the user cin>>first_No; //store the floating point value in variable first_No cout<<"Enter last number: "; //request input from the user cin>>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 cout<<"Product is : "<<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 numbers Enter first number: 15.25 Enter lastt number: 25.75 Product is : 392.688
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 <iostream> #include <conio.h> using namespace std; float mulNum(float,float); //function prototype int main() { cout<<"find Product of floating point value\n"; float f_No=40.4,s_No=20.6,product; //declaring and initializing variables product=mulNum(f_No,s_No); //calling the function and assigning the output to product variable cout<<"Product is : = "<<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
calculate Product of two floating point numbers Product is : 832.24
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 <iostream> #include <conio.h> using namespace std; float mulNum(float,float); int main() { cout<<"find Product of floating point value\n"; float f_No,s_No,product; cout<<"Enter first number: "; //ask input from the user cin>>f_No; //storing the input value in variable f_No cout<<"Enter second number: "; //ask input from the user cin>>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 cout<<"Product is : = "<<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
calculate Product of two floating point numbers Enter first number: 10.10 Enter last number: 20.20 Product is : 204.02
Suggested post
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