From ce00d57a2e0d1dc65d1ceafd87cc84de61ccdb11 Mon Sep 17 00:00:00 2001 From: juan Date: Tue, 19 Oct 2021 22:58:02 +0800 Subject: [PATCH] add 1 to 5 in midnight (noooo) --- pset4/1-question.c | 27 +++++++++++++++++++++++++++ pset4/2-ROT3.c | 23 +++++++++++++++++++++++ pset4/3-grade.c | 31 +++++++++++++++++++++++++++++++ pset4/4-primes.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 pset4/1-question.c create mode 100644 pset4/2-ROT3.c create mode 100644 pset4/3-grade.c create mode 100644 pset4/4-primes.c diff --git a/pset4/1-question.c b/pset4/1-question.c new file mode 100644 index 0000000..58a0092 --- /dev/null +++ b/pset4/1-question.c @@ -0,0 +1,27 @@ +#include + +int main(void) { + // Initialize variables + int n, temp; + scanf("%d", &n); + + scanf("%d", &temp); + int min = temp, max = temp, sum = 0; + sum += temp; + + for (int i = 0; i < n - 1; i++) { + scanf("%d", &temp); + + sum += temp; + + if (temp < min) { + min = temp; + } + if (temp > max) { + max = temp; + } + } + + printf("%d %d %d\n", sum, max, min); + return 0; +} diff --git a/pset4/2-ROT3.c b/pset4/2-ROT3.c new file mode 100644 index 0000000..0c2eede --- /dev/null +++ b/pset4/2-ROT3.c @@ -0,0 +1,23 @@ +#include + +// Declare prototypes +int process(char c); + +int main(void) { + int temp; + + while ((temp = getc(stdin)) != '\n') { + printf("%c", process(temp)); + } + printf("\n"); + + return 0; +} + +int process(char c) { + if (c >= 'a' && c <= 'z') { // If c is a - z + return (c - 'a' + 3) % 26 + 'a'; + } + else + return (c - 'A' + 3) % 26 + 'A'; // Else if c is A - Z +} diff --git a/pset4/3-grade.c b/pset4/3-grade.c new file mode 100644 index 0000000..9f0887a --- /dev/null +++ b/pset4/3-grade.c @@ -0,0 +1,31 @@ +#include + +void get_score(int s); + +int main(void) { + // Initialize variables and get input from stdin + int score; + scanf("%d", &score); + + get_score(score); + + return 0; +} + +void get_score(int s) { + if (s > 100) { + printf("The score is out of range!\n"); + } else if (s >= 90) { + printf("A\n"); + } else if (s >= 80) { + printf("B\n"); + } else if (s >= 70) { + printf("C\n"); + } else if (s >= 60) { + printf("D\n"); + } else if (s >= 0) { + printf("E\n"); + } else { + printf("The score is out of range!\n"); + } +} diff --git a/pset4/4-primes.c b/pset4/4-primes.c new file mode 100644 index 0000000..53e3c83 --- /dev/null +++ b/pset4/4-primes.c @@ -0,0 +1,39 @@ +#include + +// Function prototypes +void get_primes(void); +int is_prime(int num); + +int main(void) { + // Initialize variables + int lines; + scanf("%d", &lines); + + for (int i = 0; i < lines; i++) { + get_primes(); + } + return 0; +} + +void get_primes(void) { + int temp; // Temporary + int count = 0; + scanf("%d", &temp); + + while (temp != -1) { + if (is_prime(temp) == 0) { // is_prime returns 1 aka. true + count++; + } + scanf("%d", &temp); + } + + printf("%d\n", count); +} + +int is_prime(int num) { + for (int j = 2; j < num; j++) { + if (num % j == 0) + return 1; + } + return 0; +}