Pr.Pg Next Pg

C pyramid programs of type 4 tutorials

 

Example: Program to print pyramid of alphabets

 Sam Madam

/*WAP to print a pyramid

A A

AB BA

ABC CBA

ABCD DCBA

ABCDEEDCBA

*/

 

#include <stdio.h>

#include <conio.h>

void main()

{

for (int i=1;i<=5;i++) //for 5 loops

{

for (int j=1;j<=i;j++)

{

printf("%c ",(j+64)); //to print values

}

for (int s=1;s<=(10-(2*i));s++)

{

printf(" "); //for spaces

}

for (int k=i;k>=1;k--)

{

printf("%c ",k+64); //to print values

}

printf("\n"); //for line break

}

getch();

}

Output

 

A A

AB BA

ABC CBA

ABCD DCBA

ABCDEEDCBA

 

 

Example: Program to print pyramid of star

Sam Madam

/*WAP to print a pyramid

* *

** **

*** ***

**** ****

*********

*/

 

#include <stdio.h>

#include <conio.h>

void main()

{

for (int i=1;i<=5;i++) //for 5 loops

{

for (int j=1;j<=i;j++)

{

printf("*"); //to print values

}

for (int s=1;s<=(10-(2*i));s++)

{

printf(" "); //for spaces

}

for (int k=i;k>=1;k--)

{

printf("*"); //to print values

}

printf("\n"); //for line break

}

getch();

}

Output

  

* *

** **

*** ***

**** ****

*********

 

 

Example: Program to print pyramid of star

Sam Madam

/*WAP to print a pyramid

*********

**** ****

*** ***

** **

* *

*/

 

#include<stdio.h>

void main()

{

int i,j,k;

for(i=0;i<5;i++) //for 5 loops

{

for (j=0;j<5-i;j++)

printf("*"); //for printing *

for (k=0;k<(10-2*j);k++)

printf(" "); //for printing spaces

for (j=0;j<5-i;j++)

printf("*"); //for printing *

printf("\n"); //for line break

}

}

Output

*********

**** ****

*** ***

** **

* *


Pr.Pg border                                              Next Pg