Pyramid pattern program in c for beginners in programming language to understand the basic concepts of programming and looping like for loop and while loop.
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. Here we have executed this c program to print pyramid star pattern for beginners.
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.
//Pyramid Pattern Program in C
#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
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *