multipication

C++ Program to multiply two floating point numbers

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

operator in C++ language

 

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

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.