C++ Program To Multiply Two Floating-Point Numbers

Last Updated : 12 Aug, 2026

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

Multiply Floating Point Numbers in C++

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.

C++
#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.
Comment