✓ Link copied to clipboard
C 📅 July 1, 2026 ⏱ 5 min read

C Program to Multiply Two Floating-Point Numbers

C Program to Multiply Two Floating-Point Numbers

Multiplying numbers is a pretty common thing in programming. Whether you're adding totals or doing some scientific math, you gotta know how to handle different data types right. In this program, we’ll multiply two floating-point numbers using C. Let’s check it out.

Prerequisites for the C Program to Multiply Two Floating-Point Numbers

To write this C program, you'll need the following:

  • Understanding of float data type in C.
  • Basic arithmetic operations in C.
  • printf and scanf functions for input and output.
  • Any C compiler such as GCC 9 or newer — or just run it in the EduSeekho online compiler.

Source Code of C Program to Multiply Two Floating-Point Numbers

Here's the complete code for multiplying two floating-point numbers:

multiply_float.cC▶ Run
#include <stdio.h>

int main() {
    float a, b, product;
    // Input two floating-point numbers
    printf("Enter the first number: ");
    scanf("%f", &a);
    printf("Enter the second number: ");
    scanf("%f", &b);

    // Calculate the product
    product = a * b;

    // Display the result
    printf("Product = %.2f\n", product);
    
    return 0;
}

Try this code yourself — free

Run it in the EduSeekho online compiler. No setup needed.

▶ Open Compiler

Output of the Multiply Two Floating-Point Numbers Program

When you run the program, you can input two floating-point numbers to see their product.

Outputshell
Enter the first number: 5.5
Enter the second number: 2.1
Product = 11.55
Output of C Program to Multiply Two Floating-Point Numbers
Output of C Program to Multiply Two Floating-Point Numbers

Algorithm to Multiply Two Floating-Point Numbers in C

In this program, you input two numbers, multiply them, and print the result. Here's the step-by-step logic:

  1. Read two floating-point numbers from the user.
  2. Multiply the numbers.
  3. Print the product.
flowchart TD
  A([Start]) --> B[/Read the first floating-point number a/]
  B --> C[/Read the second floating-point number b/]
  C --> D[product = a * b]
  D --> E[/Print product/]
  E --> F([End])
Flowchart: the algorithm step by step

How the C Program to Multiply Two Floating-Point Numbers Works

Let's understand how each line of the code works to multiply two floating-point numbers.

  • #include <stdio.h>: This includes the standard input-output library for functions like printf and scanf.
  • float a, b, product;: Declares three floating-point variables to hold the input numbers and their product.
  • printf("Enter the first number: ");: Prompts the user to input the first number.
  • scanf("%f", &a);: Reads the first number into variable a.
  • printf("Enter the second number: ");: Prompts the user to input the second number.
  • scanf("%f", &b);: Reads the second number into variable b.
  • product = a * b;: Multiplies the two numbers and stores the result in product.
  • printf("Product = %.2f\n", product);: Prints the product, formatted to two decimal places.
  • return 0;: Indicates that the program executed successfully.
🧠

Quick Quiz — test your understanding

Tap an option to check your answer

What is the data type used for floating-point numbers in this program?

🎉Correct! The 'float' data type is used to handle floating-point numbers in C.
🤔Not quite. Recall that 'float' is used for numbers with decimals.

How Fast Is the C Program to Multiply Two Floating-Point Numbers?

Let's delve into the complexity of our program.

Time Complexity: O(1). The operation multiplies two numbers directly with no loops or recursion. It performs a fixed amount of work regardless of the input numbers.

Space Complexity: O(1). Only three variables are used: a, b, and product, which are floating-point numbers.

⚠️

Common mistake:Forgetting to use the right format specifier %f for floating-point input and output can mess things up or cause errors.

Key takeaway:Multiplying floating-point numbers in C is easy when you use the right data types and format specifiers.

FAQs About C Program to Multiply Two Floating-Point Numbers

Let's answer some common questions about this program.

A floating-point number is just a number with a decimal point. In C, you can use float or double to work with floating-point numbers.
float takes up less memory than double, but double gives you more precision. Go with float if you need smaller precision.
Use double or bump up the precision in the printf format specifier, like %.4f for four decimal places.
Huge numbers can overflow if they go beyond the range of the float type. Think about using double for a larger range.
Sure, just extend the code to add more variables and multiply them one after the other.

If you found this program helpful, check out these related programs:

Conclusion

Multiplying floating-point numbers in C is a breeze, but precision's important. Watch out for issues like overflow and rounding. For an extra challenge, try expanding this program to deal with more numbers or switch to using double for more precision.

Test your skills by tackling more C problems in our C language quiz, and practice coding using our online compiler.