-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistogram.c
More file actions
152 lines (142 loc) · 3.34 KB
/
histogram.c
File metadata and controls
152 lines (142 loc) · 3.34 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <stdio.h>
#include <stdlib.h>
#define VELKOSTPOLA 1001
#define STREND '\0'
#define NOMSGEDITED "Nie je k dispozicii upravena sprava\n"
void histogramprint(float pocty[26], int max) {
int i, j;
for(i=max;i>0;i--){
for (j=0;j<26;j++){
if (pocty[j]>=i){
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}
}
void histogramlegenda() {
int j;
for (j=0;j<26;j++){
printf("%c", j+65);
}
printf("\n");
}
int histogrammax(float pocty[26], int celok) {
int i, j, max=0;
for (i=0;i<26;i++){
pocty[i]=(pocty[i]/celok)*100;
if (pocty[i]<=10&&pocty[i]>0){pocty[i]=1;}
if (pocty[i]<=20&&pocty[i]>10){pocty[i]=2;}
if (pocty[i]<=30&&pocty[i]>20){pocty[i]=3;}
if (pocty[i]<=40&&pocty[i]>30){pocty[i]=4;}
if (pocty[i]<=50&&pocty[i]>40){pocty[i]=5;}
if (pocty[i]<=60&&pocty[i]>50){pocty[i]=6;}
if (pocty[i]<=70&&pocty[i]>60){pocty[i]=7;}
if (pocty[i]<=80&&pocty[i]>70){pocty[i]=8;}
if (pocty[i]<=90&&pocty[i]>80){pocty[i]=9;}
if (pocty[i]<=100&&pocty[i]>90){pocty[i]=10;}
if ( pocty[i] > max ) {
max = pocty[i];
}
}
return max;
}
void histogram(char pole2[VELKOSTPOLA], int isu){
float pocty[26] = {0};
int celok=0;
if(isu==0){
printf(NOMSGEDITED);
return;
}
char *g;
g=pole2;
while(*g!=STREND){
celok++;
switch(*g){
case 'A':
pocty[0]++;
break;
case 'B':
pocty[1]++;
break;
case 'C':
pocty[2]++;
break;
case 'D':
pocty[3]++;
break;
case 'E':
pocty[4]++;
break;
case 'F':
pocty[5]++;
break;
case 'G':
pocty[6]++;
break;
case 'H':
pocty[7]++;
break;
case 'I':
pocty[8]++;
break;
case 'J':
pocty[9]++;
break;
case 'K':
pocty[10]++;
break;
case 'L':
pocty[11]++;
break;
case 'M':
pocty[12]++;
break;
case 'N':
pocty[13]++;
break;
case 'O':
pocty[14]++;
break;
case 'P':
pocty[15]++;
break;
case 'Q':
pocty[16]++;
break;
case 'R':
pocty[17]++;
break;
case 'S':
pocty[18]++;
break;
case 'T':
pocty[19]++;
break;
case 'U':
pocty[20]++;
break;
case 'V':
pocty[21]++;
break;
case 'W':
pocty[22]++;
break;
case 'X':
pocty[23]++;
break;
case 'Y':
pocty[24]++;
break;
case 'Z':
pocty[25]++;
break;
}
g++;
}
int max = histogrammax(pocty, celok);
histogramprint(pocty, max);
histogramlegenda();
}