Problem

(What's the Value of x?) The following program uses function multiple to determine if...

(What's the Value of x?) The following program uses function multiple to determine if the integer entered from the keyboard is a multiple of some integer X. Examine the function multiple, then determine X's value.

1 // ex10_16.c

2 // This program determines whether a value is a multiple of X.

3 #include

4

5 int multiple(int num); // prototype

6

7 int main(void)

8 {

9 int y; // y will hold an integer entered by the user

10

11 puts("Enter an integer between 1 and 32000: ");

12 scanf("%d", &y);

13

14 // if y is a multiple of X

15 if (multiple(y)) {

16 printf("%d is a multiple of X\n", y);

17 }

18 else {

19 printf("%d is not a multiple of X\n", y);

20 }

21 }

22

23 // determine whether num is a multiple of X

24 int multiple (int num)

25 {

26 int mask = 1; // initialize mask

27 int mult = 1; // initialize mult

28

29 for (int i = 1; i <= 10; ++i , mask <<= 1) {

30

31 if ((num&mask) !=0) {

32 mult = 0;

33 break;

34 }

35 }

36

37 return mult;

38 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 10
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT