Loops – Arithmetic – Problem #17
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Write a program to perform the following tasks, (A) Take input two positive integer numbers ‘n’ and ‘k’. (B) Hence successively keep on taking positive integer numbers as input until you encounter ‘k’ multiples of ‘n’, i.e all the various different multiples of ‘n’ appearing for a total of ‘k’ times in the input stream. (C) Find out the maximum and the minimum among those ‘k’ multiples of ‘n’ and display them. You have to use a do-while loop for this question and cannot use arrays. Do not consider 0 or negative numbers as inputs anywhere. Initial Input: n=5 k=3 Successive Inputs: 34 23 25 78 100 32 11 85 (STOP HERE, NO MORE INPUT) Output: Maximum multiple: 100 Minimum multiple: 25 [Reason: As n=5 and k=3, you would need to stop taking successive integers as input once you encounter any 3 multiples of 5. In the given input stream, the 3 multiples of 5 are 25, 100 and 85, in that order. You stop taking further input once you encounter a total of 3 multiples of 5, i.e 85 in this case. Among the three multiples, 25, 100 and 85, 25 is the minimum and 100 is the maximum]