Program in C To Print Hollow Right Triangle Star Pattern

Errorlogger
0
/* Program to print the following output
        *****
      *    *
    *  *
  **
*
*/

#include <stdio.h>
int main()
{
    int i, j;
    //Outer loop for iterating over rows
    for(i=1; i<=5; i++)
    {
        for(j=i; j<=5; j++)
        {
            /*
             * Stars gets printed only for row=1, column=1 or column=5
             */
            if(i==1 || j==i || j==5)
            {
                printf("*");
            }
            else
            {
                //Print spaces if stars don't get printed
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !