Program to divide two numbers

Description

In this program, program will take two number as input and give division of
the two number as output. The first input stored in variable firstNumber and
second input stored in variable secondNumber. The variables firstNumber and
secondNumber are divided using the arithmetic operator / and the result is 
stored in the variable div.
example : firstNumber = 20
          secondNumber = 5
          sub = 4

C/C++

/* C Program to divide two numbers */
//Save it as DivideTwoNumbers.c

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

    float firstNumber, secondNumber, div;

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

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

    div = firstNumber / secondNumber;

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

    return 0;
}
Input:
Enter the first number : 
15
Enter the second number : 
2

Output:
The division of 15.000 and 2.000 is 7.500
Divide Two Numbers
Divide Two Numbers

Java

/* Java Program to divide two numbers */
//Save it as DivideTwoNumbers.java

import java.io.*;
import java.util.Scanner;
public class DivideTwoNumbers {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);   
        int firstNumber, secondNumber, div;
        System.out.println("Enter the first number : ");
        firstNumber = scanner.nextInt();      
        System.out.println("Enter the second number : ");
        secondNumber = scanner.nextInt();
        
        div = firstNumber / secondNumber;
        
        System.out.println("The division of "+firstNumber+" and "+secondNumber+" is "+ div);
    }
}
Input:
Enter the first number : 
10
Enter the second number : 
2

Output:
The division of 10 and 2 is 5

Related Programs

1) Add Two Numbers
2) Program to subtract two numbers
3) Program to multiply 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