万卷网 > 题目详情
题型:单选题

下面C++代码实现输出如下图形,相关说法【错误】的是?( )

请输入层数:10
0
12
345
6789
01234
567890
1234567
89012345
678901234
5678901234


int line_number, now_number;
int i, row;
cout << "请输入行数:";
cin >> line_number;
now_number = 0;
for (row = 1; row < line_number + 1; row++) { // L1
    for (i = 0; i < row; i++) { // L2
        cout << now_number;
        now_number += 1;
        if (now_number == 10) now_number = 0; // L3
    }
    cout << endl;
}
A.

代码 now_number = 0 移动到 L1 和 L2 标记的两行代码之间,效果维持不变

B.

代码 now_number += 1 修改为 now_number = 1 + now_number 效果维持不变

C.

将代码 now_number == 10 调整为 now_number > 9 效果维持不变

D.

将最后一行的 cout << endl 修改为 cout << "\n" ,效果维持不变

更新时间:2026-03-30 19:46:20 |
【知识点】 CCF—GESP C++二级

相似题推荐

单选题

下面代码用来找出输入的N个正整数中最大的一个。如果将代码段用流程图来表示,则 L1 标记的代码行应 该使用的图形是( )。

int N, max=0, val; 
cin >> N; 

while(N){ 
    cin >> val; 
    if(val > max) // L1 
        max = val; 
    N--; 
} 
cout << max;
A.

圆形框

B.

椭圆形框

C.

平行四边形框

D.

菱形框

2026-09-29
判断题

下面C++代码段执行后将输出 0-3-6-9- 。 ( )

for (int i = 0; i < 10; i++){ 
    if (i % 3) 
        continue; 
    cout << i << "-"; 
}


A.正确 B.错误
2026-09-29
单选题

下面的 C++ 代码段正常执行后其输出的数字图形是( )。

for (i = 1; i < 5; i++){ 
    for (j = 1; j < i+1; j++) 
        cout << j; 
    cout << endl; 
}
A.

1

12

123

1234

B.

1

22

333

4444

C.

1

21

321

4321

D.

4

34

234

1234

2026-09-29
判断题

C++ 语句cout << ('4' % '2' == '2' * '2' % 2); 执行后的输出是1。( )

A.正确 B.错误
2026-09-29
单选题

下面 C++ 代码段执行后,其输出是( )。

int i, j, cnt; 
cnt = 0; 
for (i = 0; i < 5; i++){ 
    i = -i; for (j = i; j < -i; j++) cnt += 1; 
    i = -i; 
} 
cout << cnt;
A.

5

B.

15

C.

20

D.

30

2026-09-29
公众号
客服 反馈
顶部