Part III 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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question

I would appreciate your help. I attached instructions to a C program. Could you copy and paste the code please?

Part III
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
sults several times using dif
ent numbers to be sure that it's 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.
Transcribed Image Text:Part III 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 sults several times using dif ent numbers to be sure that it's 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.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr