<>

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

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
TOP