Pyramid Programs in C

5 (100%) 1 vote

Pyramid Programs in C

Here is a example of c program to print pyramid structure as below:

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

Let’s start writing pyramid program

#include<stdio.h>

#define MAX	5

int main()
{
    int i,j;
    int space=4;
    /*run loop (parent loop) till number of rows*/
    for(i=0;i< MAX;i++)
    {
	    /*loop for initially space, before star printing*/
	    for(j=0;j< space;j++)
	    {
		    printf(" ");
	    }
	    for(j=0;j<=i;j++)
	    {
		    printf("* ");
	    }
		
	    printf("\n");
	    space--;	/* decrement one space after one row*/
    }
    return 0;
}

 

pyramid program in c
pyramid program in c
For any query or issue, feel free to discuss on http://discuss.eduguru.in

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: