Loading...

Pyramids of Star C Program


C Program which prints the pyramids of star Like this:

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



#include <stdio.h>
main()
{
    int row, c, n, temp;

    printf("Enter the number of rows: ");
    scanf("%d",&n);

    temp = n;

    for ( row = 1 ; row <= n ; row++ )
    {
        for ( c = 1 ; c < temp ; c++ )
            printf(" ");

        temp--;

        for ( c = 1 ; c <= 2*row - 1 ; c++ )
            printf("*");

        printf("\n");
    }
}

Also by Making Function of it:

#include <stdio.h>
void pyramid(int);
main()
{
    int n;

    printf("Enter the number of rows: ");
    scanf("%d",&n);

    pyramid(n);
}
void pyramid(int n)
{
    int temp,c,row;
    
    temp = n;

    for ( row = 1 ; row <= n ; row++ )
    {
        for ( c = 1 ; c < temp ; c++ )
            printf(" ");

        temp--;

        for ( c = 1 ; c <= 2*row - 1 ; c++ )
            printf("*");

        printf("\n");
    }
}

Rate this posting:
{[['']]}

0 comments:

Post a Comment

 
TOP