使用一个循环和 continue 语句打印图案的 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
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("
");
j = 0;
i++;
}
}
return 0;
}输出
如果运行上述程序,它将生成以下输出
* ** *** **** ***** ******
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP