The program must accept an integer N as the input. The task is to divide the largest digit by the smallest digit in N and print the result.
Boundary Condition(s):
10 <= N <= 10^9
Input Format:
The first line contains the integer N.
Output Format:
A single line contains the result of the division (rounded to 2 decimal places).
Example Input/Output 1:
Input:
4275
Output:
7.00
Explanation:
The largest digit is 7 and the smallest digit is 2. The result of 7 divided by 2 is 3.5. Hence the output is 3.5 rounded to two decimal places.
N = input().strip()
digits = [int(d) for d in N]
print(f'{max(digits)/min(digits):.2f}')
#include<stdio.h>
int main() {
char N[11];
scanf("%s", N);
int max_digit = 0, min_digit = 9;
for(int i = 0; N[i]; i++) {
int digit = N[i] - '0';
if(digit > max_digit) max_digit = digit;
if(digit < min_digit) min_digit = digit;
}
printf("%.2f", (double)max_digit/min_digit);
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
string N;
cin >> N;
int max_digit = 0, min_digit = 9;
for(char ch : N) {
int digit = ch - '0';
if(digit > max_digit) max_digit = digit;
if(digit < min_digit) min_digit = digit;
}
cout << fixed << setprecision(2) << (double)max_digit/min_digit;
return 0;
}
import java.util.Scanner;
import java.text.DecimalFormat;
public class DivMaxMinDigits {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String N = sc.next();
int max_digit = 0, min_digit = 9;
for(char ch : N.toCharArray()) {
int digit = ch - '0';
if(digit > max_digit) max_digit = digit;
if(digit < min_digit) min_digit = digit;
}
DecimalFormat df = new DecimalFormat("0.00");
System.out.println(df.format((double)max_digit/min_digit));
}
}