Due: Monday 10/04 10:00am
GitHub Submission Link: git@github.com:mks65/06_switcheroo.git
Do the following in a C program.
- Create an array large enough to store 10 ints.
- Set the first value in the array to 0.
- Populate the rest of the array with random values.
- See below for notes on random numbers
- Print out the values in this array
- Create a separate array large enough to store 10 ints.
- Create pointer variables that will point to each array.
- USING ONLY POINTER VARIABLES (that is, do not use the array variables) do the following:
- Populate the second array with the values in the first but in reverse order
- Print out the values in the second array
- Try this using both
[]
and*
.
For this assignment, do not create helper functions, put everything inside main (it won’t be too long). We will talk about passing arrays and pointers are function arguments next week.
Random Numbers
- Note: On some systems, you may be able to use other functions than the ones described below, but they are not standard for linux, so you should stay away from them for now.
- Generating a random number in C requires 2 steps
- Seeding the random number generator
srand( time(NULL) );
srand(<SEED>)
seeds the random number generator with the provided argument.- If you use the same argument to
srand()
multiple times, you will get the exact same sequence of random numbers. time(NULL)
will return the current EPOCH time, it is commonly used withsrand()
to get new random sequences.- Getting a random number
int x = rand();
- Returns the next random number in the sequence seeded by
srand()
. - Returns an
int
.
srand()
andrand()
are both in<stdlib.h>
time()
is in<time.h>