C Program to Multiply Two Floating-Point Numbers

C Program to Multiply Two Floating-Point Numbers

C program to multiply two floating-point numbers; Through this tutorial, we will learn how to multiply two floating-point numbers in the c program.

Algorithm to Multiply Two Floating Point Numbers

Use the following algorithm to write a program to multiply two floating point numbers; as follows:

  • Step 1: Start program.
  • Step 2: Read two numbers from user and store them into variables.
  • Step 3: Multiply two floating point numbers and store result in variable.
  • Step 4: Print multiply two floating point numbers.
  • Step 5: End program.

C Program to Multiply Two Floating-Point Numbers

#include <stdio.h>
int main(){
   float num1, num2, product;
   printf("Enter first Number: ");
   scanf("%f", &num1);
   printf("Enter second Number: ");
   scanf("%f", &num2);

   //Multiply num1 and num2
   product = num1 * num2;

   // Displaying result up to 3 decimal places. 
   printf("Product of entered numbers is:%.3f", product);
   return 0;
}

The output of the above c program; as follows:

Enter first Number: 3.5
Enter second Number: 5.5
Product of entered numbers is:19.250

C Program to multiply two numbers using function

#include <stdio.h>
/* Creating a user defined function product that
 * multiplies the numbers that are passed as an argument
 * to this function. It returns the product of these numbers
 */
float product(float a, float b){
    return a*b;
}
int main()
{
    float num1, num2, prod;
    printf("Enter first Number: ");
    scanf("%f", &num1);
    printf("Enter second Number: ");
    scanf("%f", &num2);

    // Calling product function
    prod  = product(num1, num2);

    // Displaying result up to 3 decimal places.
    printf("Product of entered numbers is:%.3f", prod);

    return 0;
}

The output of the above c program; as follows:

Enter first Number: 5.5
Enter second Number: 6.5
Product of entered numbers is:35.750

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published.