2018-09-18 Hot Swapping

posted Sep 18, 2018, 10:34 AM by Konstantinovich Samuel
In order do this assignment, you need to be able to generate random numbers in c. 
  • 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
      1. srand( time(NULL) );
        1. srand(<SEED>) seeds the random number generator with the provided argument.
        2. If you use the same argument to srand() multiple times, you will get the exact same sequence of random numbers.
        3. time(NULL) will return the current EPOCH time, it is commonly used with srand() to get new random sequences. 
    2. Getting a random number
      1. rand(); 
        1. Returns the next random number in the sequence seeded by srand().
        2. Returns an int.
    3. srand() and rand() are both in <stdlib.h>
    4. time() is in <time.h>
And now for the assignment:
  1. Create an array large enough to store 10 ints.
  2. Populate the array with random values.
  3. Set the last value in the array to 0.
  4. Print out the values in this array
  5. Create a separate array large enough to store 10 ints.
  6. USING ONLY POINTERS (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
  7. Print out the values in the second array
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 in a few days.

github repo name: