You are on page 1of 3

TechGeekBuzz

Techies World for Tech Geeks

Most Asked Pattern


Programs in C
Posted in C /   PROGRAM /   PROGRAMMING
LANGUAGE

Vinay Khatri Share on:


Last updated on June 10,
2022

Table of Content

Pattern programs are most commonly asked


during interviews, so here in this article, we will be
covering the top pattern programs in C.  Moreover,
the logic is universal and can be applied to
different programming languages, such as C++,
Java, and Python.

Pattern Programs in C
The patterns that we will be discussing are:

1. Solid Rectangular Star Pattern in C


2. Hollow Rectangular star Pattern in C
3. Half Pyramid Star Pattern in C
4. Inverted Half Pyramid Pattern in C
5. Full Pyramid Star Pattern in C
N. Hollow Pyramid Star Pattern
7. Inverted Hollow Half pyramid in C
P. Full Hollow Inverted Pyramid in C
9. Half Diamond Star pattern in C
10. Solid Full Diamond Pattern in C
11. Right Arrow Star Pattern in C
12. Left Arrow Star Pattern
13. Plus Star Pattern
14. X Pattern in C
15. The Diagonal Hollow Square Pattern in C
1N. Solid Rhombus Star Pattern in C
17. Hollow Rhombus Star Pattern in C
1P. Solid Mirrored Rhombus Pattern in C
19. Hollow Mirrored Rhombus Star Pattern
20. Pascal’s triangle in C
21. Floyd’s Triangle in C
22. Half Pyramid of Alphabets in C
23. Palindrome Half Pyramid Pattern in Alphabets
24. Palindrome Half Pyramid Pattern Using
Numbers in C

1. Solid Rectangular Star Pattern in C


rows: 3 columns: 5 Preview

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

Program

#include <stdio.h>

int main()
{

int rows, columns,i,j;


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

printf("\n");

/* print solid rectangle*/

for (i = 1; i <= rows; i++)


{
for (j = 1; j <= columns; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}

Output

Enter the number of rows : 3


Enter the number of columns : 5
*****
*****
*****

2. Hollow Rectangular star Pattern in


C
rows: 3 columns: 5 Preview

Howtomake
EASYmoney
onInstagram

SEEMORE

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

Program

int main()
{
int rows, columns,i, j;

printf("Enter the number of rows : "


scanf("%d", &rows);
printf("Enter the number of columns
scanf("%d", &columns);

printf("\n");
/*Logic for holow rectangle*/
for (i = 1; i <= rows; i++)

{
for (j = 1; j <= columns; j++)
{
if (i==1 || i==rows || j==1
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}

Output

Enter the number of rows : 4


Enter the number of columns : 5

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

3. Half Pyramid Star Pattern in C


stars: 6 Preview

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

Program

#include

int main()
{
int stars,i, j;;

printf("Enter the number of stars :


scanf("%d", &stars);

/*Logic for half Pyramid*/


for (i = 1; i <= stars; i++)

{
for (j = 1; j <= i; j++)
{
printf("*");
}
printf("\n");
}

return 0;
}

Output

Enter the number of stars : 6


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

4. Inverted Half Pyramid Pattern in C


stars: 6 Preview

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

Program

int main()
{

int stars,i, j;;

printf("Enter the number of stars :

scanf("%d", &stars);

/*Logic for inverted Pyramid*/


for (i = stars; i >= 1; i--)

{
for (j = 1 ; j <= i; j++)
{
printf("*");
}
printf("\n");
}

return 0;
}

Output

Enter the number of stars : 6


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

5. Full Pyramid Star Pattern in C


height=5 Preview

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

Program

#include <stdio.h>
int main()
{
int height,space,i,j,k;
printf("Enter the height of the
scanf("%d",&height);
space=height;
for( i=1;i<=height;i++)
{
for( j=1;j<space-1;j++)
{
printf(" ");
}
for( k=1;k<=2*i-1;k++)
{
printf("*");
}
space--;

printf("\n");
}
return 0;
}

Output

Enter the height of the triangle: 5


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

6. Hollow Pyramid Star Pattern


Height of Pyramid: 6 Preview

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

Program

#include<stdio.h>

int main()
{
int height,space,i,j,k;
printf("Height of Pyramid: ");
scanf("%d",&height);
space=height;
for( i=1;i<=height;i++)
{
for( j=1;j<=space-1;j++)
{
printf(" ");
}
for( k=1;k<=2*i-1;k++)
{
if(k==1 || k==2*i-1 || i==
printf("*");
else
printf(" ");
}
space--;

printf("\n");
}
return 0;
}

Output

Height of Pyramid: 6
*
* *
* *
* *
* *
***********

7. Inverted Hollow Half Pyramid in C


height = 7 Preview

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

Program

#include<stdio.h>

int main()
{
int height,i,j;
printf("Enter the height of Pyra
scanf("%d",&height);
for(i=height;i>=1;i--)
{
for( j=1;j<=i;j++)
{
if(j==1 || j==i || i==heigh
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}

Output

Enter the height of Pyramid: 7


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

8. Full Hollow Inverted Pyramid in C


height: 6 Preview

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

Program

#include <stdio.h>

int main()
{
int height,space=1,i,j,k;
printf("Enter the height of pyra
scanf("%d",&height);

for( i=height;i>=1;i--)
{
for( j=1;j<space;j++)
{
printf(" ");
}
for( k=1;k<=2*i-1;k++)
{
if(k==1 || k==2*i-1 || i==
printf("*");
else
printf(" ");
}
space++;

printf("\n");
}
return 0;
}

Output

Enter the height of pyramid: 6


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

9. Half Diamond Star Pattern in C


max stars: 7 Preview

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

Program

#include<stdio.h>

int main()
{
int max_stars,i,j;
printf("Enter the width of diamo
scanf("%d",&max_stars);
for( i=1;i<=max_stars;i++)
{
for( j=1;j<=i;j++) { printf("*");
{
for( j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}

return 0;
}

Output

Enter the width of diamond: 7


*
**
***
****
*****
******
*******
******
*****
****
***
**
*
10. Solid Full Diamond Pattern in C
width: 7 Preview

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

Program

#include<stdio.h>
int main(void) {
int width, space, stars, i, j, k;
printf("Enter the width of diamond
scanf("%d",&width);
space=width-1;
stars=1;
for( i=1;i<=width;i++)
{
for( j=1;j<=space;j++)
{
printf(" ");
}
for( k=1;k<=stars;k++) { printf(
{
space=space-1;
stars=stars+2;
}
if(space<i)
{
space=space+1;
stars=stars-2;
}
printf("\n");
}
return 0;}

Output

Enter the width of diamonds: 7


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

11. Right Arrow Star Pattern in C


width: 7 Preview

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

Program

#include<stdio.h>

int main(void) {

int width,i,j,k;
printf("Enter the width of arrow:
scanf("%d",&width);

// arrow upper part


for( i=0;i<width;i++)
{
for( j=0;j<i;j++)
{
printf(" ");
}
for( k=1;k<=width-i;k++)
{
printf("*");
}
printf("\n");
}

// arrow lower part


for( i=1;i<width;i++)
{
for( j=1;j<width-i;j++)
{
printf(" ");
}
for( k=1;k<=i+1;k++)
{
printf("*");
}
printf("\n");
}
return 0;
}

Output

Enter the width of arrow: 7


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

12. Left Arrow Star Pattern


width : 6 Preview

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

Program

#include<stdio.h>

int main(void) {

int width,i,j,k;
printf("Enter the width of arrow:
scanf("%d",&width);
for( i=1;i<=width;i++)
{
for( j=1;j<=width-i;j++)
{
printf(" ");
}
for( k=0;k<=width-i;k++)
{
printf("*");
}
printf("\n");
}
for( i=1;i<width;i++)
{
for( j=1;j<i+1;j++)
{
printf(" ");
}
for( k=1;k<=i+1;k++)
{
printf("*");
}
printf("\n");
}
return 0;
}

Output

Enter the width of arrow: 6


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

13. Plus Star Pattern


height: 7 Preview

+
+
+
+++++++
+
+
+

Program

#include<stdio.h>

int main(void) {
int height,i,j;
printf("Enter the height (odd): ")
scanf("%d", &height);
for( i=1;i<=height;i++)
{
if(i==((height/2)+1))
{
for( j=1;j<=height;j++)
{
printf("+");
}

}
else
{
for( j=1;j<=height/2;j++)
{
printf(" ");
}
printf("+");
}
printf("\n");
}
return 0;
}

Output

Enter the height (odd): 7


+
+
+
+++++++
+
+
+

14. X Pattern in C
width: 6 Preview

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

Program

#include<stdio.h>

int main(void) {
int width,space, i,j;
printf("Enter the width: ");
scanf("%d",&width);
space=2*width-1;
for( i=1;i<=space;i++)
{
for( j=1;j<=space;j++)
{
if(i==j || j==(space-i+1))
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}

Output

Enter the width: 6


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

15. The Diagonal Hollow Square


Pattern in C
rows: 8 Preview

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

Program

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

return 0;
}

Output

Enter rows: 8
********
** **
* * * *
* ** *
* ** *
* * * *
** **
********

16. Solid Rhombus Star Pattern in C


rows: 7 Preview

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

Program

#include<stdio.h>

int main()
{
int rows, i,j,k;
printf("Enter rows: ");
scanf("%d",&rows);
for( i=rows;i>=1;i--)
{
for( j=1;j<=i-1;j++)
{
printf(" ");
}
for( k=1;k<=rows;k++)
{
printf("*");
}
printf("\n");
}
return 0;
}

Output

Enter rows: 7
*******
*******
*******
*******
*******
*******
*******

17. Hollow Rhombus Star Pattern in C


rows: 7 Preview

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

Program

#include<stdio.h>

int main()
{
int rows,i,j,k;
printf("Enter rows: ");
scanf("%d",&rows);
for( i=rows;i>=1;i--)
{
for( j=1;j<=i-1;j++)
{
printf(" ");
}
for( k=1;k<=rows;k++)
{
if(i==1 || i==rows || k==
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}

Output

Enter rows: 7
*******
* *
* *
* *
* *
* *
*******

18. Solid Mirrored Rhombus Pattern in


C
rows: 7 Preview

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

Program

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

}
printf("\n");
}
return 0;
}

Output

Enter rows: 7
*******
*******
*******
*******
*******
*******
*******

19. Hollow Mirrored Rhombus Star


Pattern
rows: 7 Preview

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

Program

#include
int main()
{
int rows, i,j,k;
printf("Enter rows: ");
scanf("%d",&rows);
for( i=1;i<=rows;i++)
{
for( j=1;j<i;j++)
{
printf(" ");
}
for( k=1;k<=rows;k++)
{
if(i==1 || i==rows || k==1
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}

Output

Enter rows: 7
*******
* *
* *
* *
* *
* *
*******

20. Pascal's Triangle in C


rows: 6 Preview

1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
6 7 8 9 10 11 10 9 8 7 6

Program

#include <stdio.h>
int main() {
int i, s, r, k = 0, c1 = 0, c2 =
printf("Enter rows(r): ");
scanf("%d", &r);
for (i = 1; i <= r; ++i) {
for (s = 1; s <= r - i; ++s) {
printf(" ");
++c1;
}
while (k != 2 * i - 1) {
if (c1 <= r - 1) {
printf("%d ", i + k);
++c1;
} else {
++c2;
printf("%d ", (i + k - 2
}
++k;
}
c2 = c1 = k = 0;
printf("\n");
}
return 0;
}

Output

Enter rows(r): 6
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
6 7 8 9 10 11 10 9 8 7 6

21. Floyd's Triangle in C


rows: 6 Preview

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21

Program

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

Output

Enter rows: 6
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21

22. Half Pyramid of Alphabets in C


Last Alphabet: F Preview

A
B B
C C C
D D D D
E E E E E
F F F F F F

Program

#include<stdio.h>
int main() {
int i, j;
char input, alphabet = 'A';
printf("Enter an uppercase charac
scanf("%c", &input);
for (i = 1; i <= (input - 'A' + 1
for (j = 1; j <= i; ++j) {
printf("%c ", alphabet);
}
++alphabet;
printf("\n");
}
return 0;
}

Output

Enter an uppercase character you wan


A
B B
C C C
D D D D
E E E E E
F F F F F F

23. Palindrome Half Pyramid Patterns


in Alphabets
rows: 5 Preview

A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA

Program

#include

int main() {
int i, j, rows, c=0;

printf("Enter rows: ");


scanf("%d", &rows);

for (i = 1; i <= 2*rows; i=i+2) {


for (j = 1; j <= i; j++) {
printf("%c", 'A'+c);
if(j <= i/2)
c++;
else
c--;
}
c = 0;
printf("\n");
}
return(0);
}

Output

Enter rows: 6
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA

Note: Check out C program to print a triangle of


alphabets .

24. Palindrome Half Pyramid Pattern


Using Numbers in C
rows: 6 Preview

1
121
12321
1234321
123454321
12345654321

Program

#include

int main() {
int i, j,k, rows, c=0;

printf("Enter rows: ");


scanf("%d", &rows);

for(i=1; i<=rows; i++)


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

Output

Enter rows: 6
1
121
12321
1234321
123454321
12345654321

Conclusion
Those were some of the most popular pattern
programs in C. What are your favorite pattern
programs? Let us know in the comments. Buy the
course here to hone your skills and master the C
language.

People are also reading:

Design Love Calculator


DSA - Dynamic Programming
Convert Feet into Inches
Quick Sort in C
Convert Feet into Inches
Data Types in C
What is C?
Best C Certiccations
C Courses
C vs C++

Tags: c programming pattern programs pattern programs in c

Related Blogs

PROGRAMMING LANGUAGE

Top 10 No-Code Platforms to Build a Product


Building a product isn’t as daunting as it seems, especially with the
technologies available …

5 Mar, 2022 Read More

PROGRAMMING LANGUAGE /  PYTHON

Best way to convert string to bytes in Python 3


In this tutorial, we will write the code for how to convert the String to
a Byte in Python and vice…

5 Mar, 2022 Read More

PROGRAMMING LANGUAGE /  SQL

What is SQL? A Detailed Guide for Beginners


A database is a well-structured collection of data, and it stores and
manipulates data electronical…

5 Mar, 2022 Read More

Leave a Comment on
this Post
Enter Name

Enter Email

Comment....

Post

0 Comments

Tutorials Top Books

Python Tutorial Python Books

C++ Tutorial C++ Books

SQL Tutorial C Books

JavaScript Tutorial Java Books

CSS Tutorial PHP Books

HTML Tutorial Data Science Books

PHP Tutorial R Books

Data Structure Tutorial

Docker Tutorial

Java Tutorial

Angular Tutorial

Scala Tutorial

Top Interview Questions Top Projects

Python Interview Questions Python Projects

C++ Interview Questions C++ Projects

C Interview Questions HTML Projects

Java Interview Questions Java Projects

PHP Interview Questions PHP Projects

jquery Interview Questions Android Projects

Data Science Interview Questions JavaScript Projects

Programming Interview Questions Data Science Projects

AI Projects

TechGeekBuzz
Techies World for Tech Geeks

Get the latest tutorials and updates

Enter email address Subscribe


About Us Advertising Privacy Policy Term and Condition Blog
Write for us Roadmaps

© TechAtom Pvt. Ltd. All rights reserved.

You might also like