Programs to print pyramids using *, numbers and characters
Program to print :
*
* * *
* * * * *
* * * * * * *
* * *
* * * * *
* * * * * * *
Source Code:
#include<stdio.h>
main()
{
int i, j, k;
int n=5; //Pyramid height
for(i=1;i<=n;i++)
{
for(j=n;j>=i;j--)
{
printf(" ");
}
for(k=1;k<=(2*i)-1;k++)
{
printf("*"); //you can put any character
}
printf("\n");
}
}
main()
{
int i, j, k;
int n=5; //Pyramid height
for(i=1;i<=n;i++)
{
for(j=n;j>=i;j--)
{
printf(" ");
}
for(k=1;k<=(2*i)-1;k++)
{
printf("*"); //you can put any character
}
printf("\n");
}
}
Program to print :
* * * * * * *
* * * * *
* * *
*
* * * * *
* * *
*
Source Code:
#include<stdio.h>
main()
{
int i, j, k;
int n=5; //Pyramid height
int p=0;
for(i=n;i>0;i--)
{
for(k=0;k<p;k++)
{
printf(" ");
}
p++;
for(j=(2*i)-1;j>0;j--)
{
printf("*");
}
printf("\n");
}
}
main()
{
int i, j, k;
int n=5; //Pyramid height
int p=0;
for(i=n;i>0;i--)
{
for(k=0;k<p;k++)
{
printf(" ");
}
p++;
for(j=(2*i)-1;j>0;j--)
{
printf("*");
}
printf("\n");
}
}
Program to print :
*
* *
* * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * *
* *
*
Source Code:
#include<stdio.h>
main()
{
int i, j, k, l;
int n=5;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("*"); //you can put any character
}
printf("\n");
}
for(l=0; l<n-1; l++)
{
for(k=n-1;k>l;k--)
{
printf("*"); //you can put any character
}
printf("\n");
}
}
main()
{
int i, j, k, l;
int n=5;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("*"); //you can put any character
}
printf("\n");
}
for(l=0; l<n-1; l++)
{
for(k=n-1;k>l;k--)
{
printf("*"); //you can put any character
}
printf("\n");
}
}
Program to print :
*
* *
* * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * *
* *
*
Source Code:
#include<stdio.h>
main()
{
int i, j, k, l, m, m1;
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");
}
for(l=1;l<n;l++)
{
for(m1=0;m1<l;m1++)
{
printf(" ");
}
for(m=n-1;m>=l;m--)
{
printf("*");
}
printf("\n");
}
}
main()
{
int i, j, k, l, m, m1;
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");
}
for(l=1;l<n;l++)
{
for(m1=0;m1<l;m1++)
{
printf(" ");
}
for(m=n-1;m>=l;m--)
{
printf("*");
}
printf("\n");
}
}
0 Comments