+
+
+
+
+++++++++
+
+
+
+
/**
* C program to print the plus star pattern series
* atnyla.com
*/
#include <stdio.h>
int main()
{
int i, j, N;
printf("Enter N: ");
scanf("%d", &N);
// Run an outer loop from 1 to N*2-1
for(i=1; i<=(N * 2 - 1); i++)
{
// For the center horizontal plus
if(i == N)
{
for(j=1; j<=(N * 2 - 1); j++)
{
printf("+");
}
}
else
{
// For spaces before single plus sign
for(j=1; j<=N-1; j++)
{
printf(" ");
}
printf("+");
}
printf("\n");
}
return 0;
}
Output
Enter N: 5
+
+
+
+
+++++++++
+
+
+
+
Basic C programming, If else, For loop, Nested loop
+
+
+
+
+++++++++
+
+
+
+
Take a close look about the pattern and identify some noticeable things about it. Here are some.
N * 2 - 1 rows.N * 2 - 1 columns.N - 1 blank spaces.Based on the above observation let us write a C program to print plus star pattern.
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.