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

Find the Maximum Number using while

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a program that reads a list of integers from the user and determines the largest number in the list.

Steps to Implement

  • First, read the number of integers n that will follow.
  • Then, read n integers one by one.
  • Determine and print the maximum number among them.

Your output should exactly match the format shown in the examples below.

Constraints

n is a positive integer (n > 0). The integers can be positive, negative, or zero.

Input Format

  • The first line contains an integer n, representing the number of integers to follow.
  • The next n lines each contain one integer.

Output Format

Print a single line in the format: The max number is X, where X is the largest number in the list.

Sample Testcases

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

Sample #1
Public sample
7
-9
5
6
3
7
16
-2
The max number is 16
Sample #2
Public sample
3
10
20
5
The max number is 20
Simple case with positive integers
Sample #3
Public sample
1
42
The max number is 42
Single element case
Sample #4
Public sample
8
-100
-50
-200
-25
-75
-10
-5
-30
The max number is -5
All negative numbers with larger magnitude negatives
Sample #5
Public sample
6
0
0
-1
1
-1
1
The max number is 1
Mix of zeros, positives and negatives

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