add bupt homework

This commit is contained in:
juan 2021-09-28 19:52:33 +08:00
parent 769d2273d1
commit 26653397dd
No known key found for this signature in database
GPG key ID: 5C1E5093C74F1DC7
2 changed files with 70 additions and 0 deletions

15
pointers.c Normal file
View file

@ -0,0 +1,15 @@
#include <stdio.h>
#include <string.h>
int main(void) {
// initialize pointer variables
char *str;
char str1[20];
str = &str1;
strcpy(str1, str);
printf("%s\n", str1);
printf("%s\n", str1);
printf("%i\n", *str);
return 0;
}

55
pset2/1-basketball.c Normal file
View file

@ -0,0 +1,55 @@
#include <stdio.h>
int main(void) {
// initialize variables
int a, b;
scanf("%i %i", &a, &b);
// case 1: one team has reached 21 points. and less than 22 points
if (a >= 21 && a <= 22) {
if (b < 21) {
printf("A win");
return 0;
} else {
printf("error");
return 0;
}
}
if (b >= 21 && b <= 22) {
if (a < 21) {
printf("B win");
return 0;
} else {
printf("error");
return 0;
}
}
// case 2: one team has more points but less than 21 points.
if (a < 21 && b < 21) {
if (a > b) {
printf("A win");
return 0;
} else if (a < b) {
printf("B win");
return 0;
}
}
// case 3: one team has more points than 22
if (a > 22 || b > 22) {
printf("error");
return 0;
}
// case 4: scores are equal
if (a == b) {
if (a < 21 && b < 21) {
printf("no result");
return 0;
}
}
return 0;
}