Home > Backend Development > C++ > body text

C program to print patterns using a loop

PHPz
Release: 2023-09-09 22:25:02
forward
1327 people have browsed it

C program to print patterns using a loop

The challenge is to display the pattern using only a loop and continue statement.

Algorithm

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
Copy after login

Example

#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;
}
Copy after login

Output

If we run the above program then it will generate the following output

*
**
***
****
*****
******
Copy after login

The above is the detailed content of C program to print patterns using a loop. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template