forked from thantrieu/LearnC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBai6.4B.c
82 lines (69 loc) · 1.5 KB
/
Bai6.4B.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
struct HoTen {
char ho[20];
char dem[20];
char ten[20];
};
struct DiemMH {
float toan;
float van;
float anh;
float tbc;
};
struct SinhVien {
int ma;
struct HoTen hoVaTen;
int tuoi;
char gioiTinh[10];
struct DiemMH diem;
};
void nhapDiem(struct DiemMH* diem) {
printf("Toan: ");
scanf("%f", &diem->toan);
printf("Van: ");
scanf("%f", &diem->van);
printf("Anh: ");
scanf("%f", &diem->anh);
diem->tbc = (diem->toan + diem->van + diem->anh) / 3;
}
void nhapHoTen(struct HoTen* ten) {
printf("Ho: ");
scanf("%s", ten->ho);
printf("Dem: ");
getchar();
gets(ten->dem);
printf("Ten: ");
scanf("%s", ten->ten);
}
struct SinhVien nhapSV() {
struct SinhVien sv;
printf("Nhap ma: ");
scanf("%d", &sv.ma);
nhapHoTen(&sv.hoVaTen);
printf("Tuoi: ");
scanf("%d", &sv.tuoi);
printf("Gioi tinh: ");
scanf("%s", sv.gioiTinh);
nhapDiem(&sv.diem);
return sv;
}
void hienThiTTSV(struct SinhVien sv) {
printf("%-10d %-10s %-20s %-10s %-10d %-10s %-10.2f %-10.2f %-10.2f %-10.2f\n",
sv.ma, sv.hoVaTen.ho, sv.hoVaTen.dem, sv.hoVaTen.ten, sv.tuoi, sv.gioiTinh,
sv.diem.toan, sv.diem.van, sv.diem.anh, sv.diem.tbc);
}
int main(){
struct SinhVien dssv[100];
int slsv = 0;
struct SinhVien sv;
sv = nhapSV();
dssv[slsv++] = sv;
printf("%-10s %-10s %-20s %-10s %-10s %-10s %-10s %-10s %-10s %-10s\n",
"Ma SV", "Ho", "Dem", "Ten", "Tuoi", "Gioi Tinh",
"Diem Toan", "Diem Van", "Diem Anh", "Diem TBC");
int i;
for(i = 0; i < slsv; i++) {
hienThiTTSV(dssv[i]);
}
return 0;
}