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