From 9d9d0914aa5d6e94d137cbfeb944ec84ee40fe5f Mon Sep 17 00:00:00 2001 From: juan Date: Thu, 4 Nov 2021 19:42:37 +0800 Subject: [PATCH] add 1-3 --- pset7/1-fun.c | 26 ++++++++++++++++++++++++++ pset7/2-getDays.c | 30 ++++++++++++++++++++++++++++++ pset7/3-getDigit.c | 16 ++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 pset7/1-fun.c create mode 100644 pset7/2-getDays.c create mode 100644 pset7/3-getDigit.c diff --git a/pset7/1-fun.c b/pset7/1-fun.c new file mode 100644 index 0000000..9288f37 --- /dev/null +++ b/pset7/1-fun.c @@ -0,0 +1,26 @@ +// #include +// +// // 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; + } +} diff --git a/pset7/2-getDays.c b/pset7/2-getDays.c new file mode 100644 index 0000000..ac0a324 --- /dev/null +++ b/pset7/2-getDays.c @@ -0,0 +1,30 @@ +// #include +// +// 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; + } +} diff --git a/pset7/3-getDigit.c b/pset7/3-getDigit.c new file mode 100644 index 0000000..e566478 --- /dev/null +++ b/pset7/3-getDigit.c @@ -0,0 +1,16 @@ +#include + +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; +}