C programs to print PYRAMID patterns using nested loops.

1.)

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

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("pyramid of stars\n");
for (i=1;i<=5;i++) {
for (j=1;j<=i;j++) {
printf("*");
}
printf("\n");
}
getch();
}

2.)

1
12
123
1234
12345

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("pyramid of numbers\n");
for (i=1;i<=5;i++) {
for (j=1;j<=i;j++) {
printf("%d",j);
}
printf("\n");
}
getch();
}

3.)

1
22
333
4444
55555

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("pyramid of numbers\n");
for (i=1;i<=5;i++) {
for (j=1;j<=i;j++) {
printf("%d",i);
}
printf("\n");
}
getch();
}

4.)

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

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("pyramid of stars\n");
for (i=5;i>=1;i--) {
for (j=1;j<=i;j++) {
printf("*");
}
printf("\n");
}
getch();
}

5.)

12345
1234
123
12
1

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("pyramid of numbers\n");
for (i=5;i>=1;i--){
for (j=1;j<=i;j++) {
printf("%d",j);
}
printf("\n");
}
getch();
}

6.)

55555
4444
333
22
1

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("pyramid of numbers\n");
for (i=5;i>=1;i--){
for (j=1;j<=i;j++) {
printf("%d",i);
}
printf("\n");
}
getch();
}


7.)

1
2 3
4 5 6
7 8 9 10

#include<stdio.h>
#include<conio.h>
void main(){
int i,j,k=1;
clrscr();
printf("pyramid of number\n");
for (i=1;i<=5;i++) {
for (j=1;j<=i;j++) {
printf("%d ",k);
k++;
}
printf("\n");
}
getch();
}

8.)

15
14 13
12 11 10
  9   8   7  6
  5   4   3  2 1

#include<stdio.h>
#include<conio.h>
void main(){
int i,j,k=15;
clrscr();
printf("pyramid of number\n");
for (i=5;i>=1;i--) {
for (j=1;j<=i;j++) {
printf("%d ",k);
k++;
}
printf("\n");
}
getch();
}

9.)

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



#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("pyramid of stars\n");
for (i=1;i<=5;i++) {
for (j=1;j<=5-i;j++) {
printf(" ");
}
for (j=1;j<=2*i-1;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

10.)

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

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("pyramid of stars\n");
for (i=5;i>=1;i--) {
for (j=1;j<=5-i;j++) {
printf(" ");
}
for (j=1;j<=2*i-1;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

11.)

11111
2222
333
44
5

#include<stdio.h>
#include<conio.h>
void main(){
int i,j,k=1;
clrscr();
printf("pyramid of number\n");
for (i=5;i>=1;i--) {
for (j=1;j<=i;j++) {
printf("%d ",k);
}
k++;
printf("\n");
}
getch();
}

12.)

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

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("pyramid of stars\n");
for (i=1;i<=5;i++) {
for (j=1;j<=5-i;j++) {
printf(" ");
}
for (j=1;j<=i;j++) {
printf("*");
}
printf("\n");
}
getch();
}

13.)

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

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("pyramid of stars\n");
for (i=5;i>=1;i--) {
for (j=1;j<=5-i;j++) {
printf(" ");
}
for (j=1;j<=i;j++) {
printf("*");
}
printf("\n");
}
getch();
}

14.)

A
BC
DEF
GHIJ
KLMNO

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
char k='A';
clrscr();
printf("pyramid of number\n");
for (i=1;i<=5;i++) {
for (j=1;j<=i;j++) {
printf("%c",k);
k++;
}
printf("\n");
}
getch();
}

15.)

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

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("pyramid of stars\n");
for (i=1;i<=5;i++) {
for (j=1;j<=5-i;j++) {
printf(" ");
}
for (j=1;j<=2*i-1;j++)
{
printf("*");
}
printf("\n");
}
for (i=4;i>=1;i--) {
for (j=1;j<=5-i;j++) {
printf(" ");
}
for (j=1;j<=2*i-1;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

16.)
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********

#include<stdio.h>
#include<conio.h>
void main(){
int i,j;
clrscr();
printf("structure of pallet drum\n\n");
for (i=5;i>=1;i--) {
for (j=1;j<=5-i;j++) {
printf(" ");
}
for (j=1;j<=2*i-1;j++) {
printf("*");
}
printf("\n");
}
for (i=2;i<=5;i++) {
for (j=1;j<=5-i;j++) {
printf(" ");
}
for (j=1;j<=2*i-1;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

No comments:

Post a Comment