Write a C program using a single array of 10 integers. In the main program:
Use functions for printing and shuffling the array. You can use this shuffle function.
Initialize rand() using srand(time(0)) just once at the beginning of the main program.
Example output:
3 6 0 4 0 4 1 5 8 5 0 1 2 3 4 5 6 7 8 9 1 3 7 2 8 6 4 5 9 0Optional/extra: After putting the array elements into random order and printing, sort the array and then print again. You can write your own sort routine or use the one from the book (section 5.6).
Write a program using an array to represent a deck of 52 cards suitable for playing blackjack (i.e. suits don't matter). The array should contain 4 sets of the integers from 1 to 13, representing the cards ace, 2..10, jack, queen, king.
Use functions to initialize the array, shuffle the array (putting the elements into random order), and display the array. In the main program, use your functions to initialize the array, display the array, shuffle the array, and display it again.
Depending on how you initialize the array, the program output may look something like this:
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12 12 12 13 13 13 13 9 11 13 9 13 1 11 7 3 12 6 3 8 9 3 2 13 1 13 5 7 3 4 8 7 12 1 2 10 8 5 4 5 10 1 10 6 8 11 6 7 11 5 4 4 10 2 12 6 9 2 12or like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 12 13 9 11 13 9 13 1 11 7 3 12 6 3 8 9 3 2 13 1 13 5 7 3 4 8 7 12 1 2 10 8 5 4 5 10 1 10 6 8 11 6 7 11 5 4 4 10 2 12 6 9 2 12Optional/extra
Start with a copy of your birthday simulation program from a5/p4
and modify it to generate 40 random birthdays (instead of 30)
and use an array of counters to check for collisions,
for example: int count[366] = {0};
Use a separate variable to count the total number of collisions, for example:
int total = 0;
For each generated birthday b
(random integer in the range 1 to 365):
if count[b]
is not zero, increment the total; increment count[b]
;
print the loop index and total.
The output must be suitable for plotting (just two columns of numbers) and should be similar to the simulation shown in the second week of classes. Sample output and plot.
From the textbook, page 287:
A common normalization technique scales the values such that the minimum value goes to 0, the maximum value goes to 1, and other values are scaled accordingly. For example, using this normalization, we can normalize the values in the following array:
The equation that computes the normalized value from a value xk in the array is:
where minx and maxx represent the minimum and maximum values in the array x, respectively. If you substitute the minimum value for xk in this equation, the numerator is zero, and thus the normalized value for the minimum is zero. If you substitute the maximum value for xk in this equation, the numerator and denominator are the same value, and hence the normalized value for the maximum is 1.0.
Write a function that has a one-dimensional double array and the number of values in the array as its arguments. Normalize the values in the array using the technique presented. Assume that the corresponding function prototype is:
void normalize( double x[], int num_pts)In the main program create an array with the values shown in the example above, i.e.
double x[4] = { -2, -1, 2, 0 };Print the array, then call your normalize function to normalize the array, then print the array again.
Use functions to print the array and to find the minimum and maximum elements in the array. See chapter5_5.c
Reference: wikipedia - feature scaling - min-max normalization used in machine learning algorithms
Optional/extra: In addition to testing using the specified array of size 4, in the main program use rand() and create another array of random size in the range 10 to 20, initialized with random values in the range -20.0 to 20.0, and display it before and after normalization.