Division – Two Values

The program must accept two numbers and print the value (up to two decimal places) when they are divided.

Example Input/Output 1:
Input:
10 4

Output:
2.50

Example Input/Output 2:
Input:
20 3

Output:
6.67

Python

X, Y = map(int, input().split())
print(format(X/Y, '.2f'))

Java

import java.util.*;
public class Hello {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        System.out.printf("%.2f", (float) X / Y);
    }
}

C

#include <stdlib.h>
#include  <stdio.h>
int main()
{
    int X,Y;
    scanf("%d%d",&X,&Y);
    printf("%.2f",(float)X/Y);
}

C++

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int X, Y;
    cin >> X >> Y;
    cout << fixed << setprecision(2) << (float)X/Y;
    return 0;
}
Previous Article

Sum - Format Print

Next Article

Ten Multiples

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *