Codeforcoding

Program in c++ to multiply two floating-point numbers using function

Program in c++ to multiply two floating-point numbers using function

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

Program in c++ to multiply two floating-point numbers using function
multiply two floating-point numbers

What is multiplication

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”

 

Program to multiply of two  numbers in C++ using function

Program to find product of two  numbers

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

 

Program to find product of two  numbers – tales input from the user

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

Operator in C++ language

Data types in C++ language

Variables 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

 

Multiplication program of two floating-point numbers using function in C
Java Example to subtract two integer without using minus operator
Exit mobile version