C program to print right arrow star pattern
*****
  ****
    ***
      **
        *
      **
    ***
  ****
*****

C Programming Language Loop control in C Language (Article) Loop control in C Language (Program)

27880

Program:

/**
 * C program to print right arrow star pattern
 */

#include <stdio.h>

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

    // Input number of rows from user
    printf("Enter value of n : ");
    scanf("%d", &n);

    // Print the upper part of the arrow
    for(i=1; i<n; i++)
    {
        // Print trailing (2*rownumber-2) spaces
        for(j=1; j<=(2*i-2); j++)
        {
            printf(" ");
        }

        // Print inverted right triangle star pattern
        for(j=i; j<=n; j++)
        {
            printf("*");
        }

        printf("\n");
    }

    // Print lower part of the arrow
    for(i=1; i<=n; i++)
    {
        // Print trailing (2*n - 2*rownumber) spaces
        for(j=1; j<=(2*n - 2*i); j++)
        {
            printf(" ");
        }

        // Print simple right triangle star pattern
        for(j=1; j<=i; j++)
        {
            printf("*");
        }

        printf("\n");
    }

    return 0;
}

Output:

Enter value of n : 5
*****
  ****
    ***
      **
        *
      **
    ***
  ****
*****

Explanation:

Required knowledge

Basic C programming, For loop, Nested loop

Read more - Program to print left arrow star pattern.

Logic to print right arrow star pattern

This pattern is a combination of two patterns hence, let's first divide it into two parts.

If you have noticed total number of spaces in upper part is 2*rownumber - 2 per row and bottom part contains total 2*n - 2*rownumber spaces per row (where n is the total number of rows). If you ignore leading spaces, then the upper part star pattern is similar to inverted right triangle star pattern and bottom part to simple right triangle star pattern which I already explained how to print.


This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.