How to Draw Pyramid pattern in c language
/* To print Pyramid Pattern shown below
Pyramid Pattern
*/
int main()
{
int i,j,n;
printf("Enter no. of lines: ");
scanf( "%d",&n);
//for loop for upper pyramid
//for loop for number of lines
for(i=1;i<=n;i++)
{
//for loop for spaces
for(j=1;j<=n-i;j++)
{
printf(" ");
}
//for loop for stars in first half
for(j=1;j<=i;j++)
{
printf("* ");
}
//for loop for stars in second half
//for loop for lower pyramid
//for loop for number of lines
for(i=1;i<=n-1;i++)
{
//for loop for spaces
for(j=1;j<=i;j++)
{
printf(" ");
}
//for loop for stars in first half
for(j=1;j<=n-i;j++)
{
printf("* ");
}
//for loop for stars in second half
return 0;
}
/* To print Pyramid Pattern shown below
Pyramid Pattern
*/
int main()
{
int i,j,n;
printf("Enter no. of lines: ");
scanf( "%d",&n);
//for loop for upper pyramid
//for loop for number of lines
for(i=1;i<=n;i++)
{
//for loop for spaces
for(j=1;j<=n-i;j++)
{
printf(" ");
}
//for loop for stars in first half
for(j=1;j<=i;j++)
{
printf("* ");
}
//for loop for stars in second half
//for loop for lower pyramid
//for loop for number of lines
for(i=1;i<=n-1;i++)
{
//for loop for spaces
for(j=1;j<=i;j++)
{
printf(" ");
}
//for loop for stars in first half
for(j=1;j<=n-i;j++)
{
printf("* ");
}
//for loop for stars in second half
return 0;
}
0 comments: