-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfrequency test for random numbers in c.h
71 lines (54 loc) · 1.54 KB
/
frequency test for random numbers in c.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(void) {
int times=100;
int frequency=0;
int Random_numbers[times];
int frequent_numbers[times];
int i;
srand(time(NULL));
for(i=0;i<times;i++){ //create Random numbers
Random_numbers[i]=(rand()%7) ;
}
printf("[");
for(i=0;i<times;i++){ //Showing the array after be sortd it ;
if(i==times-1)
{
printf("%d",Random_numbers[i]);
}
else
{
printf("%d,",Random_numbers[i]);
}
frequent_numbers[i] = -1; //TO Make The frequent_numbers Empty;
}
printf("]");
printf("\n");
for(i=0; i<times; i++)
{
frequency = 1;
for(int j=i+1; j<times; j++)
{
if(Random_numbers[i]==Random_numbers[j])
{
frequency++;
frequent_numbers[j] = 0;
}
}
if(frequent_numbers[i]!=0)
{
frequent_numbers[i] = frequency;
}
}
printf("The frequency of all elements of array :\n");
for(i=0; i<times; i++)
{
if(frequent_numbers[i]!=0)
{
printf("The frequency of Number: %d",Random_numbers[i]);
printf(" is %d%c.\n",(frequent_numbers[i]*100)/times,37);
}
}
}