Program to multiply two numbers

Description

The variables firstNumber and secondNumber are multiplied using the 
arithmetic operator * and the product is stored in the variable result.

C/C++

/* C Program to multiply two numbers */
//Save it as MultiplyTwoNumber.c

#include<stdio.h>
int main(){

    float firstNumber, secondNumber, result;

    printf("Enter the first number : ");
    scanf("%f",&firstNumber);

    printf("Enter the second number : ");
    scanf("%f",&secondNumber);

    result = firstNumber * secondNumber;

    printf("The multiplication of %.3f and %.3f is %.3f",firstNumber,secondNumber,result);

    return 0;
}
Input:
Enter the first number : 
3.5
Enter the second number : 
1.2

Output:
The multiplication of 3.5 and 1.2 is 4.200

Java

/* Java Program to multiply two numbers */
//Save it as MultiplyTwoNumber.java

import java.io.*;
import java.util.Scanner;

public class MultiplyTwoNumber {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
        
            float firstNumber, secondNumber, result;

        System.out.println("Enter the first number : ");
        firstNumber = scanner.nextFloat();

        System.out.println("Enter the second number : ");
        secondNumber = scanner.nextFloat();

        result = firstNumber * secondNumber;

        System.out.println("The multiplication of "+firstNumber+" and "+secondNumber +" is "+result);
    }
}
Input:
Enter the first number : 
3.5
Enter the second number : 
1.2

Output:
The multiplication of 3.5 and 1.2 is 4.2000003

Related Programs

1) Add Two Numbers
2) Program to subtract two numbers
3) Program to divide two numbers
4) Program to find modulus of two numbers
5) Program to find Quotient and Remainder
6) Program to calculate power of a number
7) Program to calculate Permutation And Combination
8) Program to find simple interest
9) Program to calculate Gross Salary
10) Program to calculate percentage mark of student
Share Me

Leave a Reply