Starting from:

$15

Problem 3: Who are the Winners Solved

Problem statement:

Citizens of Zakadaha hold an annual Gagalafa festival to celebrate the harvest of their prized produce, the well-sought after cocoa beans Kokomoko. A lucky draw is held during the festival. Every participant is given a lucky draw number. Each year, the organizer decides on two non-zero digits, the factor-digit and the must-have-digit. These two digits need not be distinct.

A winning lucky draw number is a number that is a multiple of factor-digit as well as contains the must-have-digit. In this exercise, you are to write a function findWinners () to read in the following three inputs:

• The factor-digit, which is a non-zero digit (1 - 9). . The must-have-digit, which is also a non-zero digit (1-9).

• The number of participants, n. Lucky draw numbers will be numbered from 1 to n inclusively. You may assume that all inputs are valid. For example, if factor-digit is 3, must-have-digit is 5, and the number of participants is 100, then the number of winners is 6 (the winning numbers are 15, 45, 51, 54, 57 and 75). Your program is to count the number of winners whose lucky draw number is a multiple of factor-digit as well as contains the must-have-digit. 

Sample run #1:

Enter factor-digit: 3

Enter must-have-digit: 5

Enter the number of participants: 100

Number of winners: 6

Sample run #2:

Enter factor-digit: 9

Enter must-have-digit: 1

Enter the number of participants: 15

Number of winners: 0

Sample run #3:

Enter factor-digit: 7

Enter must-have-digit: 7

Enter the number of participants: 200

Number of winners: 5

More products