Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Written in C Not C++ or C# 1. Write a function to test whether a given number is

ID: 3746388 • Letter: W

Question

Written in C

Not C++ or C#

1. Write a function to test whether a given number is a multiple of 8. A one (1) is returned if the given number is a multiple of 8. Otherwise, a zero (0) is returned. The number to be tested is an integer and is an argument to this function.

2. Write a switch statement that will examine the value of an integer variable yy and assign one of the following values to the variable dd, depending on the value of yy:

(a)15, if yy == 1

(b)25, if yy == 2

(c) 35, if yy == 3

(d)45, if yy == 4

(e) 55, if yy == 5

3. Write a loop to compute the sum of the squares of the first 100 odd integers.

Explanation / Answer

1) int multiplOf8(int num) { if(num % 8 == 0) { return 1; } else { return 0; } } 2) switch(yy) { case 1: dd = 15; break; case 2: dd = 25; break; case 3: dd = 35; break; case 4: dd = 45; break; case 5: dd = 55; break; } 3) int num, sum = 0, i; for(i = 0; i < 100; ++i) { num = 2*i + 1; sum += (num * num); }