C Programs To Print Triangle, Pyramid, Pascal's Triangle | C Programming Code To Create Pyramid and Pattern

Programs to print triangles using *, numbers and characters

Program to print :

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

Source Code:

#include<stdio.h>
main()
{
int i, j;
int n=5; //size
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("*"); //you can put any character
}
printf("\n");
}
}

Program to print :

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

Source Code:

#include<stdio.h>
main()
{
int i, j;
int n=5; //size
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("*"); //you can put any character
}
printf("\n");
}
}

Program to print :

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

Source Code:

#include<stdio.h>
main()
{
int i, j;
int n=5; //size

for(i=0;i<n;i++)
{
for(j=n;j>i;j--)
{
printf("*"); //you can put any character
}
printf("\n");
}
}

Program to print :

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

Source Code:

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

Program to print :

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

Source Code:

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

For any query, please comment below.
SUBSCRIBE

Post a Comment

0 Comments