Exercise:
Write a C program to multiply two floating-point numbers.
Click Here to View the Solution!
#include <stdio.h>
int main() {
double a, b, product;
printf("Enter two numbers: ");
scanf("%lf %lf", &a, &b);
// Calculating product
product = a * b;
// Result up to 2 decimal point is displayed using %.2lf
printf("Product = %.2lf", product);
return 0;
}
Click Here to View the Output!
Enter two numbers: 3.4 4.5
Product = 15.30
Click Here to View the Explanation!
- This program is used to calculate the product of two floating-point numbers and print their result.
- Three double data type variables
a
,b
andproduct
are initialized. - The program requests the user to enter two floating-point numbers using the
scanf() function
and store the inputs ina
andb
respectively. - The two variables
a
andb
are them multiplied using the* operator
and their result is stored in the variableproduct
. - The
printf() method
is used to print the variableproduct
and display the result on the screen. - The program exits using the
return 0 statement
.