[Solved] print empty asterisk triangle c


you just need to think that first line should be filled with *.
Second thing is first character of every line should be *.
and last character should also be *. and in between you need to fill spaces.

int main()
{
    int n=6;
    for(int i=n-1;i>=0;i--) // using n-1, bcz loop is running upto 0
    {
        for(int j=0;j<=i;j++)
        {
            if(i==n-1 || j==0 ||i==j)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");      
    }
    return 0;
}

The condition if(i==n-1 || j==0 ||i==j)
here i==n-1 is used so that first line should be filled with *.
j==0 is used to make first character of every line *. every time when new line starts i.e j=0 it will print one * character.
i==j this is used to make last character * when i==j that is last index upto which we are running loop. so at last index it will print a *.
And for all other values it will print space as it will run else condition.

OUTPUT

******
*   *
*  *
* *
**
*

solved print empty asterisk triangle c