Skip to main content

C Program to Multiply two Floating Point Numbers

C Program to Multiply two Floating Point Numbers

In this program, user is asked to enter two numbers (floating point numbers). Then, the product of those two numbers is stored in a variable and displayed on the screen.
 
Multiplication of two number
To understand this example, you should have the knowledge of following C programming topics:

Program to Multiply Two Numbers

#include <stdio.h>
int main()
{
    double firstNumber, secondNumber, product;
    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
    product = firstNumber * secondNumber;  

    // Result up to 2 decimal point is displayed using %.2lf
    printf("Product = %.2lf", product);
    
    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.

Comments

Popular posts from this blog

C Program to Compute Quotient and Remainder

C Program to Compute Quotient and Remainder This program evaluates the quotient and remainder when an integer is divided by another integer.   To understand this example, you should have the knowledge of following C programming topics: C Programming Data Types C Programming Constants and Variables C Input Output (I/O) C Programming Operators Program to Compute Quotient and Remainder #include <stdio.h> int main (){ int dividend , divisor , quotient , remainder ; printf ( "Enter dividend: " ); scanf ( "%d" , & dividend ); printf ( "Enter divisor: " ); scanf ( "%d" , & divisor ); // Computes quotient quotient = dividend / divisor ; // Computes remainder remainder = dividend % divisor ; printf ( "Quotient = %d\n" , quotient ); printf ( "Remainder = %d" , remainder ); return 0 ; } ...

C Program to Print an Integer (Entered by the User)

C Program to Print an Integer (Entered by the User) In this program, integer entered by the user is stored in a variable. Then, that variable is displayed on the screen using printf() function.   To understand this example, you should have the knowledge of following C programming topics: C Programming Constants and Variables C Programming Data Types C Input Output (I/O) Program to Print an Integer #include <stdio.h> int main () { int number ; // printf() dislpays the formatted output printf ( "Enter an integer: " ); // scanf() reads the formatted input and stores them scanf ( "%d" , & number ); // printf() displays the formatted output printf ( "You entered: %d" , number ); return 0 ; } Output Enter a integer: 25 You entered: 25 In this program, an integer variable  number is declared. ...

C Program to Check Whether a Number is Prime or Not

C Program to Check Whether a Number is Prime or Not Example to check whether an integer (entered by the user) is a prime number or not using for loop and if...else statement. To understand this example, you should have the knowledge of following C programming topics: C if...else Statement C Programming for Loop C Programming break and continue Statement A prime number is a positive integer which is divisible only by 1 and itself. For example: 2, 3, 5, 7, 11, 13 Example: Program to Check Prime Number #include <stdio.h> int main () { int n , i , flag = 0 ; printf ( "Enter a positive integer: " ); scanf ( "%d" , & n ); for ( i = 2 ; i <= n / 2 ; ++ i ) { // condition for nonprime number if ( n % i == 0 ) { flag = 1 ; break ; } } if ( n == 1 ) { printf ( "1 is neither a prime nor a comp...