* ** *** **** ***** **** *** ** *
/**
* C program to print half diamond star pattern series.
* atnyla.com
*/
#include<stdio.h>
int main()
{
int i, j, N, columns;
/* Input number of columns from user */
printf("Enter number of columns:");
scanf("%d",&N);
columns=1;
for(i=1;i < N*2;i++)
{
for(j=1; j <= columns; j++)
{
printf("*");
}
if(i < N)
{
/* Increment number of columns per row for upper part */
columns++;
}
else
{
/* Decrement number of columns per row for lower part */
columns--;
}
/* Move to next line */
printf("\n");
}
return 0;
}
Enter number of columns: 5
*
**
***
****
*****
****
***
**
*
Basic C programming, If else, For loop, Nested loop
Read more - Program to print mirrored half diamond star pattern
* ** *** **** ***** **** *** ** *
The above pattern consist of N * 2 - 1rows. For each row columns are in increasing order till Nth row. After Nth row columns are printed in descending order.
Step by step descriptive logic to print half diamond star pattern.
columns = 1.N * 2 - 1. The loop structure should look like for(i=1; i. for(j=1; j<=columns; j++). Inside this loop print star.if(i <= N) then increment columns otherwise decrement by 1.First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.