forked from thantrieu/LearnC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbai4.9.c
67 lines (58 loc) · 979 Bytes
/
bai4.9.c
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
#include <stdio.h>
void hienThi(int*, int*, int);
void nhap(int *arr, int *n) {
*n = 0;
while(*n <= 0) {
printf("Nhap n > 0: ");
scanf("%d", n);
}
int i;
for(i = 0; i < *n; i++) {
printf("arr[%d] = ", i);
scanf("%d", &arr[i]);
}
}
int chiSo(int *b, int n, int x) {
int i;
for(i = 0; i < n; i++) {
if(b[i] == x) {
return i;
}
}
return -1;
}
void dem(int *arr, int n) {
int b[100]; // [1, 2, 5]
int dem[100]; //[5, 6, 7]
int i;
int size = 0;
for(i = 0; i < n; i++) {
dem[i] = 0;
}
for(i = 0; i < n; i++) {
int index = chiSo(b, size, arr[i]);
if(index == -1) {
b[size] = arr[i];
dem[size] = 1;
size++;
} else {
dem[index]++;
}
}
hienThi(b, dem, size);
}
void hienThi(int *b, int *dem, int n) {
printf("++++++++ KQ ++++++++\n");
printf("Gia tri, So lan\n");
int i;
for(i = 0; i < n; i++) {
printf("%d:\t%d\n", b[i], dem[i]);
}
}
int main() {
int n;
int arr[100];
nhap(arr, &n);
dem(arr, n);
return 0;
}