Pyramid Star Pattern in C

Pyramid star pattern in c program for beginners in programming language to understand the basic concepts of programming and looping like for loop and while loop.

While Loop in C

In C programming, a while loop runs a target statement repeatedly as long as a condition is true. A while loop is a control flow statement in most computer programming languages that allows code to be performed repeatedly based on a supplied Boolean condition. The while loop is similar to a looping if statement. This pyramid star pattern in c using while loop.

Post Increment and Pre Increment in C

The value is incremented by one before being assigned to the variable with pre-increment I After assigning a value to a variable, the value is incremented using the post-increment (i++) method. The increment and decrement operators are known as ++ and — in C. 

They’re unary operators, which means they only have one operand. As a result, the ++ and — operators can both come before or after the operand and have the same effect. As a result, i++ and I will have the same meaning. Before incrementing I the value of I is allocated to it.

#include <stdio.h>
int main() 
{
int i, gap, rows, k = 0;
printf("Enter the no of rows");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i, k = 0)
{
for (gap = 1; gap <= rows - i; ++gap) 
{
printf(" ");
}
while (k != 2 * i - 1) 
{
printf("* ");
++k;
}
printf("\n");
}
}

Output:

Enter the no of rows 5
        *
      * * *
    * * * * *
 * * * * * * *
* * * * * * * * *