C program to print reverse Pyramid star pattern

Write a C program to print reverse Pyramid or reverse equilateral triangle star(*) pattern series using for loop. How to print inverted pyramid or inverted equilateral triangle star pattern series using for loop in C programming. Logic to print reverse pyramid star pattern series in C program.

Example

Input

Input rows: 5

Output

Required knowledge

Basic C programming, For loop

Logic to print reverse pyramid star pattern

The above pattern is similar to the simple pyramid star pattern in reversed order. To print this we need not to make much changes in simple pyramid star pattern we only need to reverse the loop conditions of the outer loop.

Program to print reverse pyramid star pattern

/**
 * C program to print reverse pyramid star pattern 
 */

#include <stdio.h>

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

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

    for(i=n; i>=1; i--)
    {
        // Print trailing spaces
        for(j=i; j<n; j++)
        {
            printf(" ");
        }

        // Print reverse pyramid
        for(j=1; j<=(2*i-1); j++)
        {
            printf("*");
        }

        printf("\n");
    }

    return 0;
}

Output

Enter number of rows: 5
*********
 *******
  *****
   ***
    *

Happy coding 😉

Write your doubts or suggestion. I will try my best to help. You must escape source code before commenting. To format your source code paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>