
挑战是仅使用一个循环和 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 </p><p>
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("</p><p>");
j = 0;
i++;
}
}
return 0;
}如果我们运行上面的程序,那么它将生成以下输出
* ** *** **** ***** ******
以上就是使用一个循环打印图案的C程序的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号