Loops – Arithmetic – Problem #14

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

Difficulty: Medium

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.]

Back to Lab Problems
Loops/Arithmetic/Problem #14

Lab Problem Statement

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

Interactive C Compiler · Problem #14

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.