#include #include #include int main (void) { int i = 0; // Generic counter int seen[5]; // Record numbers we've seen. True or False int store[5]; // Store the numbers 1-5 in the order we see them int tot = 0; // Total for unique numbers seen int ran = 0; // Place to store random number int tot2 = 0; // Record the correct matches int l = 0; // Generic counter #2 for (i = 0; i < 5; i++) // Initialize arrays { seen[i] = 0; store[i] = 0; } srand((unsigned) time(NULL)); // Initialize RGN while (tot < 5) { ran = rand() % 5 + 1; //Generate random number between 1 and 5 if (seen[ran - 1] == 0) // Have we seen this number before? { store[l] = ran; // If so store the value of it into array store l++; // Increment l seen[ran - 1] = 1; // Mark that we've seen this number //printf("Stored %d in store[%d]\n", ran, l - 1); } for (i = 0, tot = 0; i < 5; i++) tot = tot + seen[i]; // Add up all different numbers we've seen - If all have been seen; = 5 } for (i = 0; i < 5; i++) if (store[i] == i % 5 + 1) // Go through and see if index matches stored number tot2++; printf("%d\n", tot2); }