more tests
This commit is contained in:
parent
d0f8b3e0ad
commit
1bcff515b7
22 changed files with 191 additions and 58 deletions
30
test/loop/diamond.c
Normal file
30
test/loop/diamond.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
int printf(char* format, ...);
|
||||
|
||||
|
||||
int main() {
|
||||
int n = 5; // height of the diamond
|
||||
int i;
|
||||
int j;
|
||||
|
||||
// upper half of the diamond
|
||||
for (i = 1; i <= n; i++) {
|
||||
for (j = i; j < n; j++) {
|
||||
printf(" ");
|
||||
}
|
||||
for (j = 1; j <= (2 * i - 1); j++) {
|
||||
printf("*");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// lower half of the diamond
|
||||
for (i = n - 1; i >= 1; i--) {
|
||||
for (j = n; j > i; j--) {
|
||||
printf(" ");
|
||||
}
|
||||
for (j = 1; j <= (2 * i - 1); j++) {
|
||||
printf("*");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
10
test/loop/diamond.out
Normal file
10
test/loop/diamond.out
Normal file
|
@ -0,0 +1,10 @@
|
|||
*
|
||||
***
|
||||
*****
|
||||
*******
|
||||
*********
|
||||
*******
|
||||
*****
|
||||
***
|
||||
*
|
||||
0
|
|
@ -1,20 +0,0 @@
|
|||
int printf(char* format, ...);
|
||||
|
||||
void test() {
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
for (j = 0; j < 5; j++) {
|
||||
if (i >= 2 && j >= 2 && i + j >= 5) {
|
||||
return; // Exit nested loop via return
|
||||
}
|
||||
printf("(%d, %d)%c", i, j, " \n"[j == 4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
test();
|
||||
printf("\n");
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
(0, 0) (0, 1) (0, 2) (0, 3) (0, 4)
|
||||
(1, 0) (1, 1) (1, 2) (1, 3) (1, 4)
|
||||
(2, 0) (2, 1) (2, 2)
|
||||
0
|
Loading…
Add table
Add a link
Reference in a new issue