Operating Two Floating-point Numbers in C

Write a C program that can multiply two floating numbers

Click Here to View the Solution!
#include <stdio.h>
int main() 
    {
    double x, y, product;
    printf("Enter two numbers: ");
    scanf("%lf %lf", &x, &y);

    // the function (product) calculates the product of the two floating numbers
    product = x * y;

    // %.2lf rounds off the result to the second decimal place
    printf("product = %.2lf", product);
    return 0;
}
Click Here to View the Output!
Enter two numbers: 5 8
product = 40.00
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.