13课前两题。
This commit is contained in:
70
13/Exercise01.c
Normal file
70
13/Exercise01.c
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#define MALE false
|
||||
#define FEMALE true
|
||||
|
||||
typedef struct {
|
||||
int year;
|
||||
int month;
|
||||
int date;
|
||||
} DATE;
|
||||
|
||||
typedef struct {
|
||||
int ID;
|
||||
char name[21];
|
||||
bool sex;
|
||||
DATE birthday;
|
||||
double score;
|
||||
} STUDENT;
|
||||
|
||||
double getAvg(STUDENT students[], int size) {
|
||||
double sum = 0;
|
||||
int i = 0;
|
||||
for (i = 0; i < size; i++) {
|
||||
sum += students[i].score;
|
||||
}
|
||||
sum /= size;
|
||||
return sum;
|
||||
}
|
||||
|
||||
void sortStu(STUDENT students[], int size) {
|
||||
bool moved = false;
|
||||
int i = 0;
|
||||
STUDENT tmp;
|
||||
do {
|
||||
moved = false;
|
||||
for (i = 0; i < size - 1; i++) {
|
||||
if (students[i].score < students[i + 1].score) {
|
||||
tmp = students[i];
|
||||
students[i] = students[i+1];
|
||||
students[i+1] = tmp;
|
||||
moved = true;
|
||||
}
|
||||
}
|
||||
} while (moved);
|
||||
for (i = 0; i < size; i++) {
|
||||
printf("%s: %lf\n", students[i].name, students[i].score);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
STUDENT students[10];
|
||||
int i = 0;
|
||||
// freopen("fakedata","r",stdin);
|
||||
for (i = 0; i < 10; i++) {
|
||||
printf("ID: ");
|
||||
scanf("%d", &students[i].ID);
|
||||
printf("Name(max 20 char): ");
|
||||
scanf("%20s", students[i].name);
|
||||
printf("Sex: (MALE-0/FEMLE-1)");
|
||||
scanf("%d", &students[i].sex);
|
||||
printf("Birthday (Year/Month/Date):");
|
||||
scanf("%d/%d/%d", &students[i].birthday.year, &students[i].birthday.month, &students[i].birthday.date);
|
||||
printf("Scores:\n");
|
||||
scanf("%lf", &students[i].score);
|
||||
}
|
||||
printf("The Average is: %lf\n", getAvg(students, 10));
|
||||
printf("Sort result:\n");
|
||||
sortStu(students, 10);
|
||||
return 0;
|
||||
}
|
||||
38
13/Exercise02.c
Normal file
38
13/Exercise02.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
enum weekday {sun, mon, tue, wed, thu, fri, sat};
|
||||
|
||||
int main() {
|
||||
int input = 0;
|
||||
char output[10];
|
||||
scanf("%d", &input);
|
||||
switch (input % 7)
|
||||
{
|
||||
case sun:
|
||||
strcpy(output, "Sunday");
|
||||
break;
|
||||
case mon:
|
||||
strcpy(output, "Monday");
|
||||
break;
|
||||
case tue:
|
||||
strcpy(output, "Tuesday");
|
||||
break;
|
||||
case wed:
|
||||
strcpy(output, "Wednesday");
|
||||
break;
|
||||
case thu:
|
||||
strcpy(output, "Thursday");
|
||||
break;
|
||||
case fri:
|
||||
strcpy(output, "Friday");
|
||||
break;
|
||||
case sat:
|
||||
strcpy(output, "Saturday");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
printf("%s", output);
|
||||
return 0;
|
||||
}
|
||||
59
13/fakedata
Normal file
59
13/fakedata
Normal file
@@ -0,0 +1,59 @@
|
||||
345
|
||||
aaa
|
||||
0
|
||||
2020/3/4
|
||||
3.5
|
||||
|
||||
465
|
||||
bbb
|
||||
1
|
||||
2020/3/5
|
||||
4.5
|
||||
|
||||
933
|
||||
ddd
|
||||
0
|
||||
2020/4/6
|
||||
5
|
||||
|
||||
9688
|
||||
dadg
|
||||
0
|
||||
2020/12/6
|
||||
6.8
|
||||
|
||||
33
|
||||
adfidadff
|
||||
0
|
||||
2020/4/6
|
||||
7.9
|
||||
|
||||
34555
|
||||
aaa4wt
|
||||
0
|
||||
2020/3/4
|
||||
2.5
|
||||
|
||||
463
|
||||
bbberr
|
||||
1
|
||||
2020/3/5
|
||||
6.5
|
||||
|
||||
93364
|
||||
dddade
|
||||
0
|
||||
2020/4/6
|
||||
8
|
||||
|
||||
9688243
|
||||
dadgjj
|
||||
0
|
||||
2020/12/6
|
||||
10
|
||||
|
||||
33345
|
||||
adfidafd
|
||||
0
|
||||
2020/4/6
|
||||
9
|
||||
Reference in New Issue
Block a user