Previous Next
0 / 20
Module DEMO-32-59DEMO-C-32

Digit Extremes using while

DEMO-C-32 • Programming in C

Browser-only practice

Problem Statement

Write a C program that finds the largest and smallest digits in a given integer.

Your program should read an integer from standard input and output the largest and smallest digits present in that number. For negative numbers, ignore the negative sign and consider only the digits.

For example, if the input is 5283, the largest digit is 8 and the smallest is 2. If the input is -741, the largest digit is 7 and the smallest is 1.

Special cases:

  • If the number is 0, both largest and smallest digits are 0
  • If all digits are the same, both largest and smallest will be that digit

Constraints

-10^9 ≤ N ≤ 10^9

Input Format

A single line containing an integer N (-10^9 ≤ N ≤ 10^9)

Output Format

A single line containing two integers separated by a space: the largest digit and the smallest digit in the number

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
5283
8 2
Sample case showing a positive number with different digits
Sample #2
Public sample
-741
7 1
Sample case showing a negative number
Sample #3
Public sample
0
0 0
Sample case showing zero as input
Sample #4
Public sample
777
7 7
Sample case showing all identical digits
Sample #5
Public sample
1000000000
1 0
Sample case showing large number with zeros

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings