Search Your Topic

config
Friday, 19 May 2017 04:38

C Program to Multiply two Floating Point Numbers

Written by
Rate this item
(0 votes)

Program to Multiply Two Numbers

#include <stdio.h>
int main()
{
    double firstNumber, secondNumber, productOfTwoNumbers;
    printf("Enter two numbers: ");

    // Stores two floating point numbers in variable firstNumber and secondNumber respectively
    scanf("%lf %lf", &firstNumber, &secondNumber);  
 
    // Performs multiplication and stores the result in variable productOfTwoNumbers
    productOfTwoNumbers = firstNumber * secondNumber;  

    // Result up to 2 decimal point is displayed using %.2lf
    printf("Product = %.2lf", productofTwoNumbers);
    
    return 0;
}

Output

Enter two numbers: 2.4
1.12
Product = 2.69

In this program, user is asked to enter two numbers. These two numbers entered by the user is stored in variable firstNumber and secondNumber respectively. This is done using scanf() function.

Then, the product of firstNumber and secondNumber is evaluated and the result is stored in variable productOfTwoNumbers.

Finally, the productOfTwoNumbers is displayed on the screen using printf() function.

Notice that, the result is round to second decimal place using %.2lf conversion character.

Read 702 times
Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

 Call +91 74 88 34 7779  | Email : anishsingh@live.com

toshiyas.in

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.