YouTip LogoYouTip

C Examples Product Numbers

# C Example - Multiplying Two Floating-Point Numbers [![Image 3: C Examples](#) C Examples](#) Input two floating-point numbers and calculate their product. ## Example 1 #include int main(){ float num1, num2, product; printf("Enter the first floating-point number: "); scanf("%f",&num1); printf("Enter the second floating-point number: "); scanf("%f",&num2); product = num1 * num2; printf("%.2f multiplied by %.2f equals %.2fn", num1, num2, product); return 0; } Output: Enter the first floating-point number: 3.4Enter the second floating-point number: 5.63.40 multiplied by 5.60 equals 19.04 **Explanation:** In the above example, we first declared three variables: `num1`, `num2`, and `product`, which are used to store the two input floating-point numbers and their product, respectively. Then, we used the `printf` and `scanf` functions to interact with the user, receiving the two floating-point numbers as input. Next, we multiplied `num1` and `num2` and assigned the result to the `product` variable. Finally, we used the `printf` function to print the calculated result. Note that the `%.2f` format specifier is used to limit the output floating-point number to two decimal places. The following example uses **scanf()** to accept two user-input floating-point numbers simultaneously: ## Example 2 #includeint main(){double firstNumber, secondNumber, product; printf("Enter two floating-point numbers: "); // User inputs two floating-point numbers scanf("%lf %lf", &firstNumber, &secondNumber); // Multiply the two floating-point numbers product = firstNumber * secondNumber; // Output the result, %.2lf retains two decimal places printf("Result = %.2lf", product); return 0; } Output: Enter two floating-point numbers: 1.2 2.345Result = 2.81 [![Image 4: C Examples](#) C Examples](#)
← C Examples Remainder QuotientC Examples Printf Int β†’