/** * Good use of array and passing thereof * Also demo of srand and rand * Author: gtowell * Created: Feb 2021 * **/ #include #include #include #define ARR_SIZE 10 #define TABLE_FORMAT "%c%5d %10d\n" /** * Change the internal value of the array * Doing random numbers * @param siz the array size * @param intArray the arra * **/ void changeArra(int siz, int intArr[siz]) { for (int i = 0; i < siz; i++) { int rNum = rand() % siz; intArr[i] = rNum; } } /** * Print the values of the array * @param siz the array size * @param intArray the arra * **/ void printArray(char iChar, int siz, int intArr[siz]) { for (int i = 0; i < siz; i++) { printf(TABLE_FORMAT, iChar, i, intArr[i]); } } int main(int argc, char const *argv[]) { time_t tt; srand(time(&tt)); int arr[ARR_SIZE]; for (int i = 0; i < ARR_SIZE; i++) { arr[i] = i; } printArray('a', ARR_SIZE, arr); changeArra(ARR_SIZE, arr); printArray('b', ARR_SIZE, arr); return 0; }