#include #include #include int Find(const int A[], int size, int key); void QuickPick(int A[], int size, int min, int max); void PrintTicket(const int A[], int size); // populate the array 'A' of size 'size' with random, unique values between // 'min' and 'max' inclusive // return? modified content of the array A, now populated with random, unique // values between min and max void QuickPick(int A[], int size, int min, int max) { int newNum; int i; for (i=0; i < size; i++) { do { newNum = (rand() % (max-min+1)) + min; }while(i != 0 && Find(A, i, newNum) == 1); A[i] = newNum; } } void PrintTicket(const int A[], int size) { int i; // loop counter for the array index for (i=0; i < size; i++) { printf("%d ", A[i]); } printf("\n"); } // search for 'key' in array 'A' of size 'size' // return 1 if found, 0 if not // use linear search method int Find(const int A[], int size, int key) { int i; // loop counter for the array index for (i=0; i < size; i++) { if (A[i] == key) return 1; } return 0; } int main() { int LotteryNumbers[6]; int c; int lucky = 0; srand(time(NULL)); for (c =0; c < 1000; c++) { QuickPick(LotteryNumbers, 6, 1, 49); PrintTicket(LotteryNumbers, 6); lucky += Find(LotteryNumbers, 6, 27); } printf("Your lucky number appeared %d times.\n", lucky); return 0; }