使用一个循环打印图案的C程序
挑战在于仅使用一个循环并使用continue语句显示模式。
阿尔戈里斯
START
Step 1 -> declare start variables i and j to 0 with number of rows in n to 6
Step 2 -> Loop For i=1 and i<=n
IF j<i
Print *
Increment j by 1
Continue
End IF
IF j=1
Print \n
Set j=0
Increment i by 1
End IF
Step 3 -> End For Loop
STOP示例
#include <stdio.h>
int main() {
int i, j=0;
int n = 6;
for ( i = 1; i <= n; ) {
if( j < i ) {
printf("*");
j++;
continue;
}
if(j == i) {
printf("\n");
j = 0;
i++;
}
}
return 0;
}输出结果
如果我们运行上面的程序,那么它将生成以下输出
* ** *** **** ***** ******
热门推荐
10 直播生孩子祝福语简短
11 写给情侣祝福语 浪漫简短
12 职场祝福语大全 简短精辟
13 Q穷人结婚祝福语简短
14 超市中秋祝福语简短最新
15 简短霸气的考试祝福语
16 新年祝福语和语句简短
17 给老师祝福语简短创意
18 商业mc祝福语大全简短