All pastes #762983 Raw Edit

Mine

public ini v1 · immutable
·published 2007-11-06 01:34 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <time.h>int main (void){int i = 0; // Generic counterint seen[5]; // Record numbers we've seen. True or Falseint store[5]; // Store the numbers 1-5 in the order we see themint tot = 0; // Total for unique numbers seenint ran = 0; // Place to store random numberint tot2 = 0; // Record the correct matchesint l = 0; // Generic counter #2for (i = 0; i < 5; i++) // Initialize arrays{seen[i] = 0;store[i] = 0;}srand((unsigned) time(NULL)); // Initialize RGNwhile (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);}