English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

C Program Multiplies Two Floating-point Numbers

Comprehensive Collection of C Programming Examples

In this example, the product of the two floating-point numbers entered by the user will be calculated and printed on the screen.

The program multiplies two numbers

#include <stdio.h>
int main() {
    double a, b, product;
    printf("Enter two numbers: ");
    scanf("%lf %lf", &a, &b);  
 
    // Multiply
    product = a * b;
    //Using %.2lf shows decimal places after2The result of the bit
    printf("Product = %.2lf", product);
    
    return 0;
}

Output result

Enter two numbers: 2.4
1.12
Product = 2.69

In this program, the user is required to input two numbers to store in variables a and b.

printf("Enter two numbers: ");
scanf("%lf %lf", &a, &b);

Then calculate the product of a and b, and store the result in product.

product = a * b;

Finally, use printf() to display the product on the screen.

printf("Product = %.2lf", product);

Please note that the result uses %.2Round the character to two decimal places after the decimal point.

Comprehensive Collection of C Programming Examples