In this tutorial, we will discuss the concept of program in c++ to multiply two floating-point numbers using function
In this topic, we are going to learn how to multiply two floating-point numbers using the function in C++ language
The multiplication is a method of combining a group of equal size. The multiplication is an arithmetic operation inverse of division
It is one of the four basic operation of arithmetic calculation others being addition,subtraction,division
The multiplication of two numbers means, it is the operation one number is combining within another using multiply(*) operator.
The answer of a multiplication operation is called as “product”
The program calculates the product of the given floating point numbers using function in C++ language
Program 1
#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 first_No=30.4,second_No=15.6,product; //declaring and initializing variables product=mulNum(first_No,second_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
find Product of floating point value Product is := 474.24
The program allows the user to enter two floating-point numbers and then it calculates the multiplication of the given numbers using function in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; float mulNum(float,float); int main() { cout<<"find Product of floating point value\n"; float first_No,last_No,product; cout<<"Enter first number: "; //ask input from the user cin>>first_No; //storing the input value in variable first_No cout<<"Enter second number: "; //ask input from the user cin>>last_No; //storing the input value in variable last_No product=mulNum(first_No,last_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
find Product of floating point value Enter first number: 12.24 Enter last number: 20.40 Product is := 474.24
Suggested for you
Data types in C++ language
Similar post
Find product of two numbers using function in C++ language
Find product of two numbers using recursion in C++ language
Multiply two numbers in C language
Multiply two numbers in Python language
Multiply two numbers in Java language
Multiply of two floating-point numbers in Java
Multiply of two floating-point numbers in C
Multiply of two floating-point numbers in C++
Multiply of two floating-point numbers in Python
Python code to Calculate sum of odd and even in a list In this tutorial,…
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…