使用一个循环打印图案的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; }

输出

如果我们运行上面的程序,那么它将生成以下输出

*
**
***
****
*****
******

以上就是使用一个循环打印图案的C程序的详细内容。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。