/*
Manar Abouhenidi
C program for The lottery,
The lottery is a program that asks the user for 7 positive numbers,
and check if its matchs with the computer random numbers, it also sort the user numbers and print it in two order ways
,the user order and the numeric order.
Source of light
´´´´´´´´´¶¶*..**..*
´´´´´´´´´¶¶¶ .*.*.*.
¶¶¶´´´´´¶¶´¶*..**.*.
´¶¶¶¶¶¶¶¶´´¶*.*.**..**.
´´´¶¶´´´´´´¶¶¶¶¶¶¶¶¶*.*.*.*.*.
´´´´´¶¶´¶¶´´´´¶¶¶¶*.*.**.
´´´´¶¶´´´´´¶¶¶.**.**.
´´´¶¶´¶¶¶¶´´¶*.*.*.**.
´´¶¶¶¶¶´´¶¶´¶´´´´´´´´¶*.**.*.*.*
´¶¶´´´´´´´´¶¶¶´´´´´´¶¶*..**.*.
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <time.h>
int i,j,n;/* declartions for variables mainly used for loops and pointers*/
int userinput[7];/* array for users input*/
int array[7]={0,0,0,0,0,0,0};/* array for random numbers */
void random (void) /* functions to generate the random number */
{
int s;/* declartion variable to store the random number*/
int k;/* declartion variable for the foor loop*/
srand(time(NULL)); /* for generating random number */
printf(" The list of random numbers is \n\n"); /* printing instrections of the random number*/
for (k=0;k<7;k++) /* for loop to generate the random number 7 times*/
{
do{
s = 1+ (rand() % 50 ); /* saving the random number into a variable */
array[k]= s;/*storing the variable of the random number into an array */
} while (unique(s,array)!=0);
/*if the random number is repeated call unoque and replace the duplicate number with another random */
printf(" %i ",s);/* printing the random number */
}
}
int unique (int x,int array[]) /*replasing duplicates in the array*/
{
//int i;
int duplicate=0;
for(x; x<7; x++)
{
if(x==array[i])
///////////////////////////////////
duplicate=1;
// printf(" %i ",array[i]);
return(duplicate);
}
}
void main (void)
{
random();
}
Aucun commentaire:
Enregistrer un commentaire