* *
* *
* *
* *
*
* *
* *
* *
* *
/**
* C program to print X star pattern series
* atnyla.com
*/
#include <stdio.h>
int main()
{
int i, j, N;
int count;
printf("Enter N: ");
scanf("%d", &N);
count = N * 2 - 1;
for(i=1; i<=count; i++)
{
for(j=1; j<=count; j++)
{
if(j==i || (j==count - i + 1))
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
Enter N: 5
* *
* *
* *
* *
*
* *
* *
* *
* *
Step by step descriptive logic to print X star pattern.
N * 2 - 1 rows and columns. Hence run an outer loop to iterate through rows with structure for(i=1; i<= count; i++) (where count = N * 2 - 1).N * 2 - 1 columns. Therefore, run inner loop as for(j=1; j<=count; j++).if(i == j).if(j == count - i + 1).First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.