Floating-point values are commonly used in C++ for calculations involving decimal numbers. The result of multiplying two such values depends on the precision supported by the chosen data type.
- C++ provides float, double, and long double data types for representing floating-point values.
- The multiplication operator (*) is used to calculate the product of two floating-point numbers.
For example
Input: A = 1.2, B = 3.0
Output: 3.6

C++ Program to Multiply Two Floating-Point Numbers
The following program multiplies two float values using the multiplication (*) operator and stores the result in the product variable.
#include <iostream>
using namespace std;
// Creating a user-defined function
// called mul_floatnumbers that
// multiplies the numbers passed to
// it as an input. It gives you the
// product of these numbers.
float mul_floatnumbers(float a, float b) { return a * b; }
// Driver code
int main()
{
float A = 1.2, B = 3.0, product;
// Calling mul_floatnumbers function
product = mul_floatnumbers(A, B);
// Printing the output
cout << product;
return 0;
}
Output
3.6
Explanation
- A and B store the two floating-point values.
- The multiply() function uses the * operator to calculate their product.
- The result is stored in product and printed using std::cout.