使用一個迴圈和 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