Due: Monday 10/04 10:00am

Do the following in a C program.

  1. Create an array large enough to store 10 ints.
  2. Set the first value in the array to 0.
  3. Populate the rest of the array with random values.
    • See below for notes on random numbers
  4. Print out the values in this array
  5. Create a separate array large enough to store 10 ints.
  6. Create pointer variables that will point to each array.
  7. 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
    1. 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 with srand() to get new random sequences.
        1. Getting a random number
    • int x = rand();
    • Returns the next random number in the sequence seeded by srand().
    • Returns an int.
  • srand() and rand() are both in <stdlib.h>
  • time() is in <time.h>