
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print Pattern Using One Loop in C
The challenge is to display the pattern using one loop only and with continue statement.
Algorith
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
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("
"); j = 0; i++; } } return 0; }
Output
If we run above program then it will generate following output
* ** *** **** ***** ******
Advertisements