c program to print pyramid

c program to print pyramid figure with * or asterisk – one

#include<stdio.h>
#include<conio.h>

int main()
{
    for(int i=0; i<=5; i++)
    {
            for(int j=0; j<i; j++)
            {
                    printf(" * ");
            }
            printf("\n");
    }
    getch();
}


print pyramid
print pyramid

c program to print pyramid figure with * or asterisk – two

#include<stdio.h>
#include<conio.h>

int main()
{
    for(int i=5; i>=0; i--)
    {
            for(int j=i; j>0; j--)
            {
                    printf(" * ");
            }
            printf("\n");
    }
    getch();
}


print pyramid
print pyramid

c program to print given pyramid with * or asterisk – Three

#include<stdio.h>
#include<conio.h>

int main()
{
    for(int i=0; i<=5; i++)
    {
            for(int k=1; k<=5-i; k++)
            {
                    printf(" ");
            }
            for(int j=0; j<i; j++)
            {
                    printf(" * ");
            }
            printf("\n");
    }
    getch();
}


print pyramid
print pyramid

c program to print pyramid figure with * or asterisk – Four

#include<stdio.h>
#include<conio.h>

int main()
{
    for(int i=5; i>=0; i--)
    {
            for(int j=0; j<i; j++)
            {
                    printf(" * ");
            }
            printf("\n");
            for(int k=0; k<=5-i; k++)
            {
                    printf(" ");
            }
    }
    getch();
}


print pyramid
print pyramid

c program to print pyramid figure with * or asterisk – Five

#include<stdio.h>
#include<conio.h>
int main()
{
    int  i, k;
    for ( i = 1 ; i <= 5 ; i++)
    {
        for ( k = 1 ; k <= i ; k++ )
            printf("*");

        printf("\n");
    }

    for ( i = 5 - 2 ; i>= 0 ; i-- )
    {
        for ( k = i ; k >= 0 ; k-- )
            printf("*");

        printf("\n");
    }

    getch();
}


print pyramid

c program to print pyramid figure with * or asterisk – Six

#include<stdio.h>
#include<conio.h>

int main()
{
    for(int i=0; i<=5; i++)
    {
            for(int k=5; k>=i; k--)
            {
                    printf(" ");
            }
            for(int j=0; j<i; j++)
            {
                    printf("*");
            }
            printf("\n");
    }
    getch();
}


print pyramid
print pyramid

c program to print pyramid figure with * or asterisk – Seven

#include<stdio.h>
#include<conio.h>
int main()
{
    int  i, k, l;
    for ( i = 0 ; i <= 5 ; i++)
    {
            for(int k=1; k<=5-i; k++)
            {
                    printf(" ");
            }
            for(int j=0; j<i; j++)
            {
                    printf("*");
            }
            printf("\n");
    }

    for ( i = 5 - 2 ; i>= 0 ; i-- )
    {
        for( l=3-i; l>=0; l--)
        {
             printf(" ");
        }
        for ( k = i ; k >= 0 ; k-- )
        {
            printf("*");
        }
        printf("\n");
    }

    getch();
}


c program to print pyramid
c program to print pyramid

c program to print pyramid figure with * or asterisk – Eight

#include<stdio.h>
#include<conio.h>

int main()
{
    for(int i=1; i<=10; i=i+2)
    {
            for(int k=1; k<=10-i; k=k+2)
            {
                    printf(" ");
            }
            for(int j=1; j<=i; j++)
            {
                    printf("*");
            }
            printf("\n");
    }
    getch();
}


c program to print pyramid
c program to print pyramid

c program to print pyramid figure with * or asterisk – Nine

#include<stdio.h>
#include<conio.h>

int main()
{
    for(int i=1; i<=10; i=i+2)
    {
            for(int k=1; k<=10-i; k=k+2)
            {
                    printf(" ");
            }
            for(int j=1; j<=i; j++)
            {
                    printf("*");
            }
            printf("\n");
    }
    for(int i=9; i>=1; i=i-2)
    {
            for(int k=10-i; k>=0; k=k-2)
            {
                    printf(" ");
            }
            for(int j=1; j<=i; j++)
            {
                    printf("*");
            }
            printf("\n");
    }                
    getch();
}


Output :

c program to print pyramid

c program to print pyramid figure with * or asterisk – Ten

#include<stdio.h>
#include<conio.h>

int main()
{
    for(int i=9; i>=1; i=i-2)
    {
            for(int k=10-i; k>=0; k=k-2)
            {
                    printf(" ");
            }
            for(int j=1; j<=i; j++)
            {
                    printf("*");
            }
            printf("\n");
    }
    getch();
}


c program to print pyramid
c program to print pyramid

15 thoughts on “c program to print pyramid”

    1. this calculation is made to print one space first time the loop run, two spaces in the second time the loop run.
      when the value of i=9 first time then the value of then the value of k is 1 cz k=10-i and i=9. next time the value of i will b 7(i=7) cz i=i-2 or i=9-2. then the value of k=3 and the k loop will run two times and it will print two spaces cz 3>=1 and after runnig once the value of k will become 1 czk=k-2 or k=3-2 and 1>=1. this whole process will run for 5 times and a design of as shown above will appear.
      we can also make same design as follows:-
      main()
      {
      int a=0,i,j,k;
      clrscr();
      for(i=4;i>=1;i–)
      {
      for(j=i;J<=4;j++)
      {
      printf(" ");
      }
      a=i*2+1;
      for(k=1;k<=a;k++)
      {
      printf("*");
      }
      printf("\n");
      }
      getch();
      }

    1. this is not defined anywhere in the computer that “i” is row and “j” is column. a break line function “\n” is used to break the current line and print in the next line. :)

Add Comment Register



Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>