In: Computer Science
Please solve me this question and send me the video clip how to do it
This problem contains loops, sorting arrays, random generation, and variable matching.
Include an analysis (data requirements) and algorithm in your reply.
Write a “lottery engine” program to simulate drawing lottery numbers. You will draw 7 numbers, randomly selected from 1 to 16.
a) Allow the user to enter their own selection of numbers first,
Example numbers: 2 3 7 9 10 11 15
b) then run your “lottery engine” to select the “winning numbers”. Numbers are drawn randomly.
Use the clock as the seed value for your random function (Hint: use “srand(clock());” ).
c) Be sure to remove duplicate entries.
d) Print out the draw result as it was generated (unsorted), then sort the array and print out the sorted numbers.
Example output:
“
Draw unsorted: 2 12 16 14 7 13 1
Draw sorted: 1 2 7 12 13 14 16
“
e) Then print out the matching numbers selected by the user:
f) Also print the sorted user selection and draw results and matching numbers to a TXT file called “Results.txt”.
Example output
“
Draw sorted: 1 2 7 12 13 14 16
User’s sorted: 2 3 7 9 10 11 15
Matching numbers: 2 – 7
“
#include<stdio.h> #include<stdlib.h> #include<time.h> // generate_random() function to generate array of random no. void generate_random(int *a, int n) { { int main(); int i, n, j; time_t t; n = 7; /* Intializes random number generator */ srand((unsigned) time(&t)); /* Print 5 random numbers from 0 to 50 */ for (i = 0; i < n; i++) { printf("%d\n", rand() % 16); } } int j, temp, i; // Passed starting address and size to generate array of random numbers generate_random(a, n); // Displaying the random array printf("\n The random array: "); for (i = 0; i < n; i++) printf(" %d ", a); for (i = 1; i < n; i++) { for (j = 0; j < n - i; j++) { /* To sort in ascending order, change '<' to '>' to implement descending order sorting */ if (a[j + 1] < a[j]) { temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; } } } // Displaying the sorted array. printf("\n The sorted array: "); for (i = 0; i < n; i++) printf(" %d ", a); printf("\n \n"); }