Signup/Sign In

C Program To Print Plus Star Pattern

learn c Language

Logic To Print The Plus Star Pattern In C Program:

  • Get the input from the user to print the plus star pattern,
  • The condition to print plus star pattern is x*2-1,
  • The Centerline of the plus should also satisfy the condition x*2-1,
  • In other lines, only one star only printed after x-1 spaces.

C Program To Print The Plus Star Pattern In C Program:


#include <stdio.h>

int main()
{
    int i, j, N;

    printf("Enter The Number Of Rows To Print Plus Star Pattern: ");
    scanf("%d", &N);

    // Code Block To Run An Outer Loop
    for(i=1; i<=(N * 2 - 1); i++)
    {
        
        if(i == N)
        {
            for(j=1; j<=(N * 2 - 1); j++)
            {
                printf("+");
            }
        }
        else
        {
            // Code Block To Print The spaces 
            for(j=1; j<=N-1; j++)
            {
                printf(" ");
            }
            printf("+");
        }

        printf("\n");
    }

    return 0;
}

Output:

Plus Pattern