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

Write a C program that generates a random number from the following set: 1,4,7,1

ID: 3630798 • Letter: W

Question

Write a C program that generates a random number from the following set:
1,4,7,10,13,16

I was able to get this in a certain way but NOT how the instructor wants it done. His hints to do it his way are as follows:
Analysis:
1) They start at 1 and stop at 16.
2) They are incremented by 3

Base on the analysis:
1) if we try rand() % 16 will give us numbers between 0 and 15. Some of these numbers are not in the provided set.

2) since these numbers are multiples of 3 then I would want * 3 somewhere in my solution

3) since it starts with 1 and not 0 then I would need to add one to it.

4) Now looking at the numbers again: (4 is 1* 3 + 1) (7 is 2*3 + 1) (10 is 3*3 + 1) (13 is 3 * 4 + 1) (16 is 5*3 + 1)



Explanation / Answer

you missed the main catch here
please follow this

1) first we will generate a random number using

a = rand();

now get % with 6 not with 16

a = a%6           here you get a values as 0,1,2,3,4,5 now multiply by 3

a = a*3            here you get values as 0,3,6,9,12,15 now add 1

a = a++           after this you get a values as 1,4,7,10,13,16

you need not worry about which number pops out

only the value from the above set will result eventually

use this method to write the code

or if you want just answer please use this link

http://www.cramster.com/answers-oct-11/computer-science/random-number-generation-write-program-generates-random-number-fo_1560044.aspx?rec=0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote