Float Multiplication
Program to multiply two floating-point numbers
BeginnerTopic: Basic Programs
C++ Float Multiplication Program
This program helps you to learn the fundamental structure and syntax of C++ programming.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
float num1, num2, product;
cout << "Enter first number: ";
cin >> num1;
cout << "Enter second number: ";
cin >> num2;
product = num1 * num2;
cout << fixed << setprecision(2);
cout << "Product of " << num1 << " and " << num2 << " is: " << product << endl;
return 0;
}Output
Enter first number: 3.5 Enter second number: 2.5 Product of 3.5 and 2.5 is: 8.75
Understanding Float Multiplication
This program demonstrates floating-point arithmetic. We use float data type for decimal numbers. The iomanip header provides setprecision() to control decimal places. fixed and setprecision(2) formats the output to 2 decimal places.
Note: To write and run C++ programs, you need to set up the local environment on your computer. Refer to the complete article Setting up C++ Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your C++ programs.