This commit is contained in:
juan 2021-11-04 19:42:37 +08:00
parent 75ce9f4b1d
commit 9d9d0914aa
No known key found for this signature in database
GPG key ID: 5C1E5093C74F1DC7
3 changed files with 72 additions and 0 deletions

26
pset7/1-fun.c Normal file
View file

@ -0,0 +1,26 @@
// #include <stdio.h>
//
// // Function prototypes
// int fun(int input);
//
// int main(void)
// {
// // Initialize variables
// int x;
// scanf("%d", &x);
//
// printf("%d\n", fun(x));
// return 0;
// }
int fun(int input) {
if (input > 100) {
return input * input - 24;
} else if (input > 10) {
return input * 3 - 11;
} else if (input >= 1) {
return input * 2 - 1;
} else {
return input;
}
}

30
pset7/2-getDays.c Normal file
View file

@ -0,0 +1,30 @@
// #include <stdio.h>
//
// int getDays(int year, int month);
//
// int main() {
// int year, month;
//
// scanf("%d%d", &year, &month);
// printf("There are %d days in month %d year %d.", getDays(year, month), month,
// year);
//
// return 0;
// }
int getDays(int year, int month) {
if (month == 2) {
if (year % 4 == 0 && year % 100 != 0) {
return 29;
} else if (year % 100 == 0 && year % 400 == 0) {
return 29;
} else {
return 28;
}
} else if (month == 1 || month == 3 || month == 5 || month == 7 ||
month == 8 || month == 10 || month == 12) {
return 31;
} else {
return 30;
}
}

16
pset7/3-getDigit.c Normal file
View file

@ -0,0 +1,16 @@
#include <stdio.h>
int getDigit(long long n);
int main() {
long long n;
int len;
scanf("%lld", &n);
len = getDigit(n);
if (len > 1)
printf("The integer %lld has %d digits.\n", n, len);
else
printf("The integer %lld has %d digit.\n", n, 1);
return 0;
}