'Im such a genius\

This commit is contained in:
juan 2021-10-19 23:51:15 +08:00
parent ce00d57a2e
commit 0bdac22c20
No known key found for this signature in database
GPG key ID: 5C1E5093C74F1DC7
2 changed files with 96 additions and 0 deletions

25
pset4/5-squares.c Normal file
View file

@ -0,0 +1,25 @@
#include <stdio.h>
// Function prototypes
int dividable(int n);
int main(void)
{
// Initialize variables and get input
int n, sum = 0;
scanf("%d", &n);
for (int i = 1; i < n; i++) {
if (dividable(i)) {
sum += i;
}
}
printf("%d\n", sum * sum);
return 0;
}
int dividable(int n) {
return (n % 3 == 0 && n % 7 == 0) ? 1 : 0;
}

71
pset4/6-graph.c Normal file
View file

@ -0,0 +1,71 @@
#include <stdio.h>
// Function prototypes
void print_block(int n, int m); // Print the pattern
// n: columns
// m: rows
void print_row(int n, int m); // Print a line of row, called bu print_block
// n: number of columns m: position of row
// n: number of columns, see print_column
// m: ranging from 0 to 3
// m == 0: |*****|*****|*****|
// m == 1: | | | | | | |
// m == 2: |--+--|--+--|--+--|
// m == 3: | | | | | | |
void print_column(int n,
int m); // Print a single character, called by print_row
// n: type of char in a single line
// m: type of char in multiple lines
// m == 0: |***** n is defined by the position in the line with particular m
// m == 1: | |
// m == 2: |--+--
// m == 3: | |
int main(void) {
// Initialize variables and read input
int row, col;
scanf("%d", &row);
scanf("%d", &col);
// The magic starts here
print_block(col, row);
return 0;
}
void print_block(int n, int m) {
for (int i = 0; i < m * 4; i++) {
print_row(n, i % 4);
}
print_row(n, 0); // The last line
}
void print_row(int n, int m) {
for (int i = 0; i < n * 6; i++) {
print_column(i % 6, m);
}
print_column(0, m); // The last char
printf("\n");
}
void print_column(int n, int m) {
if (n == 0) {
printf("|");
} else if (n == 1 || n == 2 || n == 4 || n == 5) {
if (m == 0) {
printf("*");
} else if (m == 2) {
printf("-");
} else {
printf(" ");
}
} else if (n == 3) {
if (m == 0) {
printf("*");
} else if (m == 2) {
printf("+");
} else {
printf("|");
}
}
}