Home C Programming Language / Programs / C program to print plus star pattern + + + + +++++++++ + + + +
🚀 Programming Example

C program to print plus star pattern
    +
    +
    +
    +
+++++++++
    +
    +
    +
    +

👁 2,938 Views
💻 Practical Program
📘 Step Learning
Write a C program to print plus star pattern series using for loop. How to print plus star pattern series using loop in C program. Logic to print plus star pattern in C programming.

💻 Program Code

/**
 * 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;
}
                        

🖥 Program Output

Output
Enter N: 5
    +
    +
    +
    +
+++++++++
    +
    +
    +
    +
                            

📘 Explanation

Required knowledge

Basic C programming, If else, For loop, Nested loop

Logic to print plus star pattern

 

    +
    +
    +
    +
+++++++++
    +
    +
    +
    +

 

Take a close look about the pattern and identify some noticeable things about it. Here are some.

  1. The pattern consists of N * 2 - 1 rows.
  2. When you look to the center horizontal plus line i.e. +++++++++ this line. It also consists of N * 2 - 1 columns.
  3. For every other row, single plus symbol is printed after N - 1 blank spaces.

Based on the above observation let us write a C program to print plus star pattern.

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

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.

🔥 Practice suggestion

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.