0% found this document useful (0 votes)
0 views13 pages

Pattern Programming in C (4)

The document contains multiple examples of C programs that generate various types of pyramids and patterns using asterisks, numbers, and letters. Each example includes the code, a brief description of the pattern, and is attributed to Er. Gaurab Mishra. The patterns range from half pyramids to inverted pyramids and Floyd's triangle.

Uploaded by

anujbhandari400
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views13 pages

Pattern Programming in C (4)

The document contains multiple examples of C programs that generate various types of pyramids and patterns using asterisks, numbers, and letters. Each example includes the code, a brief description of the pattern, and is attributed to Er. Gaurab Mishra. The patterns range from half pyramids to inverted pyramids and Floyd's triangle.

Uploaded by

anujbhandari400
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Example 1: Half Pyramid of *

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

#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i)
{
for (j = 1; j <= i; ++j)
{
printf("* ");
}
printf("\n");
}

return 0;
}

Example 2: Half Pyramid of Numbers

1
12
123
1234
12345

Compiled By: Er.Gaurab Mishra


#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i)
{
for (j = 1; j <= i; ++j)
{
printf("%d ", j);
}
printf("\n");
}
return 0;
}

Example 3: Half Pyramid of Numbers

1
22
333
4444
55555

#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i)
{
for (j = 1; j <= i; ++j)

Compiled By: Er.Gaurab Mishra


{
printf("%d ", i);
}
printf("\n");
}
return 0;
}

Example 4: Inverted half pyramid of *


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

#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i)
{
for (j = 1; j <= i; ++j)
{
printf("* ");
}
printf("\n");
}
return 0;
}

Example 5: Inverted half pyramid of numbers


12345
1234
123

Compiled By: Er.Gaurab Mishra


12
1

#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i)
{
for (j = 1; j <= i; ++j)
{
printf("%d ", j);
}
printf("\n");
}
return 0;
}

Example 6: Inverted half pyramid of numbers

55555
4444
333
22
1

#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i)

Compiled By: Er.Gaurab Mishra


{
for (j = 1; j <= i; ++j)
{
printf("%d ", i);
}
printf("\n");
}
return 0;
}

Example 7:

*****
*****
*****
*****
* * * * *_

#include<stdio.h>
int main()
{
int n;

printf("Enter the number of rows: ");


scanf("%d",&n);

for(int r=1; r<=n; r++)


{
for(int c=1; c<=n; c++)
{
printf("* ");
}
printf("\n");
}

return 0;

Compiled By: Er.Gaurab Mishra


}

Example 8:

12345
12345
12345
12345
12345

#include<stdio.h>
int main()
{
int n;

printf("Enter the number of rows: ");


scanf("%d",&n);

for(int r=1; r<=n; r++)


{
for(int c=1; c<=n; c++)
{
printf("%3d",c);
}
printf("\n");
}

return 0;
}

Example 9:

11111
22222

Compiled By: Er.Gaurab Mishra


33333
44444
55555

#include<stdio.h>
int main()
{
int n;

printf("Enter the number of rows: ");


scanf("%d",&n);

for(int r=1; r<=n; r++)


{
for(int c=1; c<=n; c++)
{
printf("%3d",r);
}
printf("\n");
}

return 0;
}

Example 10:

a a a a a
b b b b b
c c c c c
d d d d d
e e e e e

#include<stdio.h>
int main()
{
int n;

Compiled By: Er.Gaurab Mishra


printf("Enter number of rows: ");
scanf("%d",&n);

for(int r=1; r<=n; r++)


{
for(int c=1; c<=n; c++)
{
printf("%3c",r+96);
}
printf("\n");
}

return 0;
}

Example 11:

AAAAA
BBBBB
CCCCC
DDDDD
EEEEE

#include<stdio.h>
int main()
{
int n;

printf("Enter number of rows: ");


scanf("%d",&n);

for(int r=1; r<=n; r++)


{
for(int c=1; c<=n; c++)
{

Compiled By: Er.Gaurab Mishra


printf("%3c",r+64);
}
printf("\n");
}

return 0;
}

Example 12:

ABCDE
ABCDE
ABCDE
ABCDE
ABCDE

#include<stdio.h>
int main()
{
int n;

printf("Enter the number of rows: ");


scanf("%d", &n);

for(int r=1; r<=n; r++)


{
for(int c=1; c<=n; c++)
{
printf("%3c",c+64);
}
printf("\n");
}

return 0;
}

Compiled By: Er.Gaurab Mishra


Example 13:

abcde
abcde
abcde
abcde
abcde

#include<stdio.h>
int main()
{
int n;

printf("Enter the number of rows: ");


scanf("%d",&n);

for(int r=1; r<=n; r++)


{
for(int c=1; c<=n; c++)
{
printf("%3c",c+96);
}
printf("\n");
}

return 0;
}

Example 14: Floyd's Triangle.

1
2 3
4 5 6
7 8 9 10

Compiled By: Er.Gaurab Mishra


#include <stdio.h>
int main()
{
int rows, i, j, number = 1;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= i; ++j)
{
printf("%3d ", number);
++number;
}
printf("\n");
}
return 0;
}

Example 15: Full Pyramid of *

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

#include<stdio.h>
int main()
{
int n, r, c, s;

printf("Enter number of rows: ");


scanf("%d",&n);

for(r=1;r<=n;r++)
{

Compiled By: Er.Gaurab Mishra


for(s=1;s<=n-r;s++)
{
printf(" ");
}
for(c=1;c<=(2*r-1);c++)
{
printf("*");
}
printf("\n");
}

return 0;
}

Example 16: Inverted Full Pyramid

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

#include<stdio.h>
int main()
{
int n, r, c, s;

printf("Enter number of rows: ");


scanf("%d",&n);

for(r=n;r>=1;r--)
{
for(s=1;s<=n-r;s++)
{
printf(" ");
}
for(c=1;c<=r;c++)
{
printf("* ");
}
printf("\n");
}

Compiled By: Er.Gaurab Mishra


return 0;
}

Compiled By: Er.Gaurab Mishra

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy