Loops – Arithmetic – Problem #14
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
You have ‘n’ number of balls numbered from 1 through n (1,2,3,.......,n). You are playing a game where you select any two cards each of which has some integer number printed over it. Your task is to choose only those balls whose associated numbers are a multiple of either of the two numbers printed on the cards that you have selected (i.e any one or both the card numbers). Write a program for this. Your input should be three integer numbers, ‘n’ representing the number of balls and ‘x’ and ‘y’, each representing one of the two numbers on the cards that you select. Your output should be those balls (i.e the number associated with the balls) that satisfy the game criteria. Print “Game Lost” in case no balls can be selected. You can assume all positive integer values including 1 but excluding 0 for ‘n’, ‘x’ and ‘y’. Example 1: Input: n = 20 x = 4 y = 7 Output: 4 7 12 14 16 20 [Reason: The numbers on the output balls all satisfy the condition that they are either a multiple of 4 or 7 or both.]