Algorithm


     1. Include Header File: `#include ` includes the standard input/output library for functions like printf and scanf.
     2. Main Function: int main() is the starting point of the program.
     3. Variable Declaration: double a, b, product; declares three variables of type double to store the two input numbers (a and b) and their product (product).
     4. User Input: printf("Enter two numbers: "); prompts the user to enter two numbers, and scanf("%lf %lf", &a, &b); reads these numbers from the user and stores them in variables a and b.
     5. Calculation: product = a * b; calculates the product of the two input numbers and stores the result in the variable product.
     6. Output: printf("Product = %.2lf", product); displays the product with two decimal points.
     7. Return Statement: return 0; indicates that the program has executed successfully.

Code Examples

#1 Program to Multiply Two Numbers

Code - C Programming

#include <stdio.h>
int main() {
    double a, b, product;
    printf("Enter two numbers: ");
    scanf("%lf %lf", &a, &b);  
 
    // Calculating product
    product = a * b;

    // %.2lf displays number up to 2 decimal point
    printf("Product = %.2lf", product);
    
    return 0;
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter two numbers: 2.4
1.12
Product = 2.69

#2 Code Example with C Programming to enter two number

Code - C Programming

printf("Enter two numbers: ");
scanf("%lf %lf", &a, &b); 
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter two numbers: 2.4
1.12
Product = 2.69

#3 Code Example with C Programming to evaluated

Code - C Programming

product = a * b;
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter two numbers: 2.4
1.12
Product = 2.69

#4 Code Example with C Programming

Code - C Programming

printf("Product = %.2lf", product);
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter two numbers: 2.4
1.12
Product = 2.69
Advertisements

Demonstration


C Programing to Multiply Two Floating-Point Numbers-DevsEnv

Next
Appending into a File in C Programming