10501
题目
[0.1] 使用循环语句,按下列要求打印字符。
txt
1
11
111
1111
11111
1
2
3
4
5
2
3
4
5
txt
1
1111
111111111
1111111111111111
1111111111111111111111111
1
2
3
4
5
2
3
4
5
txt
A
AB
ABC
ABCD
ABCDE
1
2
3
4
5
2
3
4
5
txt
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
1
2
3
4
5
2
3
4
5
txt
A
BC
DEF
GHIJ
KLMNO
1
2
3
4
5
2
3
4
5
答案
(1)
c
#include <stdio.h>
int main() {
int rows = 5;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
printf("1");
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
(2)
c
#include <stdio.h>
int main() {
int rows = 5;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i * i; j++) {
printf("1");
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
(3)
c
#include <stdio.h>
int main() {
int rows = 5;
for (int i = 0; i < rows; i++) {
for (int j = 0; j <= i; j++) {
printf("%c", 'A' + j);
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
(4)
c
#include <stdio.h>
int main() {
int rows = 5;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < rows - 1 - i; j++) {
printf(" ");
}
for (int j = 0; j <= i; j++) {
printf("%c", 'A' + j);
}
for (int j = i - 1; j >= 0; j--) {
printf("%c", 'A' + j);
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(5)
c
#include <stdio.h>
int main() {
int rows = 5;
char current = 'A';
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
printf("%c", current);
current++;
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14