add 1 to 5 in midnight (noooo)

This commit is contained in:
juan 2021-10-19 22:58:02 +08:00
parent 1aa3e03e87
commit ce00d57a2e
No known key found for this signature in database
GPG key ID: 5C1E5093C74F1DC7
4 changed files with 120 additions and 0 deletions

27
pset4/1-question.c Normal file
View file

@ -0,0 +1,27 @@
#include <stdio.h>
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;
}

23
pset4/2-ROT3.c Normal file
View file

@ -0,0 +1,23 @@
#include <stdio.h>
// 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
}

31
pset4/3-grade.c Normal file
View file

@ -0,0 +1,31 @@
#include <stdio.h>
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");
}
}

39
pset4/4-primes.c Normal file
View file

@ -0,0 +1,39 @@
#include <stdio.h>
// 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;
}