How to use while loop In C Language
The while loops check the condition until the condition is false. If the condition is true then enter into the loop and execute the statements.
C++
#include <stdio.h> int main() { int i = 0, j = 0; int rows = 5; // while loop check the condition until the given // condition is false if it is true then enteres in to // the loop while (i < rows) { // this loop will print the pattern while (j <= i) { printf ( "* " ); j++; } j = 0; i++; printf ( "\n" ); } return 0; } |
Output
* * * * * * * * * * * * * * *
Time complexity: O(n2) where n is given input rows
Auxiliary space: O(1)
C Program For Printing Simple Half Right Star Pyramid Pattern
Here, we will develop a C Program To Print Simple Half Right Star Pyramid Pattern using two approaches i.e.
- Using for loop
- Using while loop
Input:
rows = 5
Output:
* * * * * * * * * * * * * * *