Multiply Two Floating-Point Numbers in C


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 and product are initialized.
  • The program requests the user to enter two floating-point numbers using the scanf() function and store the inputs in a and b respectively.
  • The two variables a and b are them multiplied using the * operator and their result is stored in the variable product.
  • The printf() method is used to print the variable product and display the result on the screen.
  • The program exits using the return 0 statement.
%d bloggers like this: