Program in C To Print Right Arrow Star Pattern

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

#include <stdio.h>

int main()
{
    int i, j;

    //Prints the upper part of the arrow
    for(i=1; i<=5; i++)
    {
        //Prints trailing (2*rownumber-2) spaces
        for(j=1; j<=(2*i-2); j++)
        {
            printf(" ");
        }

        //Prints inverted right triangle star pattern
        for(j=i; j<=5; j++)
        {
            printf("*");
        }

        printf("\n");
    }

    //Prints lower part of the arrow
    for(i=1; i<=5; i++)
    {
        //Prints trailing (2*5 - 2*rownumber) spaces
        for(j=1; j<=(2*5 - 2*i); j++)
        {
            printf(" ");
        }

        //Prints simple right triangle star pattern
        for(j=1; j<=i; j++)
        {
            printf("*");
        }

        printf("\n");
    }

    return 0;
}

Post a Comment

1Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete
Post a Comment

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

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