C program to print reversed mirrored right triangle star pattern

Write a C program to print reversed mirrored right triangle star(*) pattern series of n rows using for loop. How to print mirrored right triangle star pattern using for loop in C programming. Logic to print reversed mirrored right triangle star pattern in C program.

Example

Input

Input rows: 5

Output

Required knowledge

Basic C programming, For loop

Must know - Program to print inverted right triangle star pattern

.

Logic to print reversed mirrored right triangle star pattern

If you look to above pattern and inverted right triangle star pattern you will find that both are similar with one exception. This pattern contains extra trailing spaces. Spaces are also arranged in a specific pattern i.e. each row contains total row_number - 1 spaces.

Program to print reverse mirrored right triangle star pattern

/**
 * C program to print reverse mirrored right triangle star pattern
 */

#include <stdio.h>

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

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

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

        // Print right triangle
        for(j=i; j<=n; 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>