Loops – Arithmetic – Problem #7

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: Medium

Problem Statement

2. Write a program that will prompt the user to enter a sequence of positive integer values. At any time, your program should display the two largest values entered so far and also the two smallest values. When the user has entered only one value, for the second largest and second smallest numbers your program should display "Value h as not yet been entered". Your program should terminate when the user enters any negative number. For example: Enter numbers: 1 Largest number: 1 Second largest number: Value Not yet entered Smallest number:1 Second smallest number: Value Not yet entered Enter numbers: 1 2 5 4 Largest number: 5 Second largest number: 4 Smallest number: I Second smallest number: 2 Enter numbers: 1 2 5 4 8 2 Largest number: 8 Second largest number:5 Smallest number: 1 Second smallest number: 2 Enter numbers: 1 2 5 4 8 2 1 1 Largest number: 8 Second largest number: 5 Smallest number: 1 Second smallest number: 2 Enter numbers: 1 2 5 4 8 2 1 1 -10 <Program terminates>

Back to Lab Problems
Loops/Arithmetic/Problem #7

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #7

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.