C program to print reverse right triangle star pattern

Write a C program to print reverse/inverted right triangle star(*) pattern series using for loop. How to print reverse/inverted right triangle star pattern series of n rows using for loop in C programming. The pattern with 5 row should look like:
*****
****
***
**
*

Required knowledge:

Basic C programming, For loop
Before printing this pattern logic of printing right triangle star pattern is recommended.

Program:

/**
 * Reverse right triangle star pattern program in C
 */

#include <stdio.h>

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

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

    for(i=1; i<=n; i++)
    {
        for(j=i; j<=n; j++)
        {
            printf("*");
        }
       
        //Moves to the next line/row
        printf("\n");
    }

    return 0;
} 


Output
X
_
Enter value of n: 5
*****
****
***
**
*


Screenshot:

Reverse right triangle star pattern program in C

Happy coding ;)


Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

No comments:

Post a Comment