Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You can generate a random number in C using the following code: int myRandomNumber; srand(time(NULL)); // seed the random number generator myRandomNumber = rand(); //

You can generate a random number in C using the following code: int myRandomNumber; srand(time(NULL)); // seed the random number generator myRandomNumber = rand(); // each time you call this function there will be a different random number. Generate a random number, and output it. Use if statements to determine if the number is odd or even, and output a message to that effect. Similarly, output if the number is divisible by 3, and if it is divisible by 10. Use the % operator to achieve this. Run the program, and print the results several times using different numbers to be sure that its working. Hint: In C you can not declare variables after you write executable code. For example if you call the srand function, and then declare some more variables after that call, the program will not compile. The compiler messages are not very helpful. Put all the variable declarations at the top of the function.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions