C pattern programs are critical in every interview question. Most of us just give up when it comes to pattern programs. But these questions will make you understand practically, based on mathematical logic and matrices' fundamentals.

This article will cover star patterns, number patterns, alphabet patterns, and some unique pattern programs.

Let’s deal with different C Pattern programs through the following docket.

#### Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN Stack

## Star Pattern

### Pattern 1: Right-Angle Triangle

#include <stdio.h>

int main()

{

int rows = 5;

for (int i = 1; i <= rows; ++i) //Outer loop for rows

{

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

{  //Inner loop for Col

printf("* "); //Print *

}

printf("\n"); //New line

}

}

### Pattern 2: Inverted Right-Angle Triangle in a Start Pattern

#include <stdio.h>

int main()

{

int i, rows = 5;

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

{  //For Loop for Row

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

{

printf("* ");

}

printf("\n"); //New line

}

}

### Pattern 3: Arrow-Shaped Pattern

#include <stdio.h>

int main()

{

int i, rows = 5;

for (int i = 0; i <= rows - 1; i++) { //For Loop for Row

for (int j = 0; j <= i; j++) { //For Loop for Col

printf("*" " "); //prints * and blank space

}

printf(" \n"); // new line

}

for (int i = rows - 1; i >= 0; i--) { //For Loop for Row

for (int j = 0; j <= i - 1; j++) { //For Loop for Col

printf("*" " "); //prints * and blank space

}

printf("\n"); //New line

}

}

#### Learn From The Best Mentors in the Industry!

Automation Testing Masters Program

### Pattern 4: Mirrored Right-Angle Triangle

#include <stdio.h>

int main()

{

int i, j, rows = 5;

for (i = 0; i < rows; i++) {

for (j = 2 * (rows - i); j >= 0; j--) { //For Loop for Row

printf(" "); // Print Spaces

}

for (j = 0; j <= i; j++) { //For Loop for col

//For Loop for Col

printf("*" " "); //prints * and blank space

}

printf("\n"); //New line

}

}

### Pattern 5: Inverted Mirrored Right-Angle Triangle

#include <stdio.h>

int main()

{

int i, j,k, rows = 5;

for (int i = rows; i >= 1; i--) {

for (int j = rows; j > i; j--) {

printf(" "); // Prints Blank space

}

for (int k = 1; k <= i; k++) {

printf("*"); //prints * and blank space

}

printf("\n"); //New line

}

}

### Pattern 6: Mirrored Arrow-Shaped Star Pattern

#include <stdio.h>

int main()

{

int i, j,k, rows = 5;

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

for (int j = i; j < rows; j++) { //Rows Loop

printf(" "); // Blank Space

}

for (int k = 1; k <= i; k++) { //Cols Loop

printf("*"); // Prints *

}

printf("\n");

}

for (int i = rows; i >= 1; i--) {

for (int j = i; j <= rows; j++) { //Rows Loop

printf(" ");  // Prints blank spaces

}

for (int k = 1; k < i; k++) { //Col Loop

printf("*"); //prints * and blank space

}

printf("\n"); //New line

}

}

#### Learn 15+ In-Demand Tools and Skills!

Automation Testing Masters Program

### Pattern 7: Pyramid Star Pattern Program

#include <stdio.h>

int main()

{

int i, j, rows = 5;

for (int i = 0; i < rows; i++) {

for (int j = rows - i; j > 1; j--) { //Loop for blank space

printf(" "); //Print Space

}

for (int j = 0; j <= i; j++) { //loop for star

printf("* "); //prints * and blank space

}

printf("\n"); //New line

}

}

### Pattern 8: Inverted Pyramid

#include <stdio.h>

int main()

{

int i, j,k, rows = 5;

for (int i = 0; i <= rows - 1; i++) { //For loop for Rows

for (int j = 0; j <= i; j++) { //For loop for Col

printf(" "); // blank space

}

for (int k = 0; k <= rows - 1 - i; k++) {

printf("*"  " "); //prints * and blank space

}

printf("\n"); //New line

}

}

#### Unleash a High-paying Automation Testing Job!

Automation Testing Masters Program

### Pattern 9: Diamond Star Pattern

#include <stdio.h>

int main()

{

int  j,x, rows=5 ,blank=1;

blank = rows - 1;

for (j = 1; j <= rows; j++) {

for (x = 1; x <= blank; x++) {

printf(""); //print blank space

}

blank--;

for (x = 1; x <= 2 * j - 1; x++) {

printf("*"); //prints * and blank space

}

printf("\n"); //New line

}

blank = 1;

for (j = 1; j <= rows - 1; j++) {

for (x = 1; x <= blank; x++) {

printf(" "); //Print Spaces

}

blank++;

for (x = 1; x <= 2 * (rows - j) - 1; x++) {

printf("*"); //Print Star

}

printf("\n"); //Print new line

}

}

#### Become an Automation Test Engineer in 11 Months!

Automation Testing Masters Program

### Pattern 10: Upper Inverted Pyramid and Lower Pyramid

#include <stdio.h>

int main()

{

int rows=5 ;

for (int i = 0; i <= rows - 1; i++) {

for (int j = 0; j < i; j++) {

printf(" "); //Print blank space

}

for (int k = i; k <= rows - 1; k++) {

printf("*"  " "); //Print star and blank space

}

printf("\n"); //New line

}

//For lower Pyramid

for (int i = rows - 1; i >= 0; i--) {

for (int j = 0; j < i; j++) {

printf(" "); //Print spaces

}

for (int k = i; k <= rows - 1; k++) {

printf("*"  " "); //Print Star and Space

}

printf("\n"); //Print new line

}

}

### Pattern 11: Right Diagonal Star Pattern

#include <stdio.h>

int main()

{

int i, j;

for (i = 1; i <= 5; i++) {

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

printf(" "); //Print blank space

}

printf("*\n");//Print new line

}

}

### Pattern 12: X Star Pattern

#include <stdio.h>

int main()

{

int i, j, rows =5;

for (i = rows; i >= 1; i--) {

for (j = i; j < rows; j++) {

printf(" ");//print spaces

}

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

if (j == 1 || j == (2 * i - 1))//Logic for printing star

printf("*");

else

printf(" ");//if logic fails print space

}

printf("\n");

}

//Lower Inverted V pattern

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

for (j = i; j < rows; j++) {

printf(" ");//Print spaces

}

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

if (j == 1 || j == (2 * i - 1))//Logic for printing star

printf("*");

else

printf(" ");//if logic fails print space

}

printf("\n");

}

}

#### Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN Stack

### Pattern 13: Inverted v Star Pattern

#include <stdio.h>

int main()

{

int out, in;

int rows = 5;

int x = 5;

int y = 5;

for (out = 1; out <= rows; out++) {

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

if (in == x || in == y) {

printf("*");

} else {

printf(" ");

}

}

x--;

y++;

printf("\n");

}

}

### Pattern 14: V Star Pattern

#include <stdio.h>

int main()

{

int n = 5;

int i, j;

for (i = n - 1; i >= 0; i--) {

for (j = n - 1; j > i; j--) {

printf(" "); //Print Space

}

printf("*"); //Print star

for (j = 1; j < (i * 2); j++)

printf(" ");//Print space

if (i >= 1)

printf("*");

printf("\n");//Enter newline

}

}

### Pattern 15: Pyramid Star Pattern

#include <stdio.h>

int main()

{

int rows = 5;

int i,j,k;

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

for (int j = i; j < rows; j++) {

printf(" ");

}

for (int k = 1; k <= (2 * i - 1); k++) {

if (k == 1 || i == rows || k == (2 * i - 1)) {

//Logic for printing Pattern

printf("*"); //Print Star

} else {

printf(" ");  //Print Spaces

}

}

printf("\n");

}

}

#### Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN Stack

### Pattern 16: Inverted Star Pyramid

#include <stdio.h>

int main()

{

int rows = 5;

int i,j,k;

//Row input

for (int i = rows; i >= 1; i--) {

for (int j = i; j < rows; j++) {

printf(" "); //Print Spaces

}

for (int k = 1; k <= (2 * i - 1); k++) {

if (k == 1 || i == rows || k == (2 * i - 1)) { //logic to print Pattern

printf("*"); //Ture prints star

} else {

printf(" "); //False prints spaces

}

}

printf("\n");

}

}

### Pattern 17: Hollow Square Pattern

#include <stdio.h>

int main()

{

int n=10,m=10;

int i, j;

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

for (j = 1; j <= m; j++) {

if (i == 1 || i == n || j == 1 || j == m) //Logic to print

printf("*"); //Tue?, print star

else

printf(" "); //Tue?, print space

}

printf("\n");

}

}

### Pattern 18: Hollow Square Pattern

#include <stdio.h>

int main()

{

int i,j, rows=10;

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

{

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

{

if(i==1 ||i==rows||j==1||j==rows-i+1||i==j||j==rows)

{

printf("*");

}

else

{

printf(" ");

}

}

printf("\n");

}

return 0;

}

### Pattern 19: Square Star Pattern

#include <stdio.h>

void main()

{

int rows=5;

for(int i=0;i<rows;i++)

{

for(int j=0;j<rows;j++)

{

printf("*");

}

printf("\n");

}

}

#### Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN Stack

### Pattern 20: Hollow Rhombus Star Pattern

#include <stdio.h>

int main()

{

int i,j,k,rows=5;

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==1 || k==rows)

printf("*");

else

printf(" ");

}

printf("\n");

}

return 0;

}

### Pattern 21: Half Diamond Star Pattern

#include<stdio.h>

int main()

{

int rows=5,i,j;

//prints upper half diamond

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

{

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

{

printf("*");

}

printf("\n");

}

//prints lower-half diamond

for( i=rows-1;i>=1;i--){

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

printf("*");

}

printf("\n");

}

return 0;

}

Following, let’s have a look at the number pattern programs in c

## Number Pattern

### Pattern 22: Right-Angle Triangle Number Pattern

#include <stdio.h>

int main()

{

int rows = 5;

int i, j, k = 1;

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

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

printf("%d", j); //Print j value and space

}

printf("\n");

}

}

### Pattern 23: Floyd’s Triangle

#include <stdio.h>

int main()

{

int rows = 5;

int i, j, k = 1;

for (i = 1; i <= 5; i++) {

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

printf("%d",k++); //Floyd’s triangle logic(prints K value and increments on every iteration)

}

printf("\n");

}

}

### Pattern 24: Pascals Program

#include<stdio.h>

void main() {

int rows=5, temp=1,i,j,k;

for (i=0; i<rows; i++) {

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

printf(" ");

for (k=0; k<=i; k++) {

if (k==0 || i==0)

temp = 1;

else

temp=temp*(i-k+1)/k;

printf("%2d", temp);

}

printf("\n");

}

### Pattern 25: Square Number Pattern

#include <stdio.h>

int main()

{

int rows = 5;

int i, j;

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

int num;

if (i % 2 == 0) {

num = 0;

for (int j = 1; j <= rows; j++) {

printf("%d",num);

num = (num == 0) ? 1 : 0;

}

} else {

num = 1;

for (int j = 1; j <= rows; j++) {

printf("%d",num);

num = (num == 0) ? 1 : 0;

}

}

printf("\n");

}

}

Let’s move ahead with the alphabet pattern programs.

## Alphabet Pattern

### Pattern 26: Right-Angle Triangle Alphabet Pattern

#include<stdio.h>

void main()

{

int i,j,rows=5;

int alphabet=64;

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

{

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

{

printf("%c",(char)(j+alphabet));

}

printf("\n");

}

}

### Pattern 27: Inverted Right-Angle Triangle

#include <stdio.h>

int main()

{

int rows=5;

int alphabet = 65;

for (int i = rows - 1; i >= 0; i--)

{

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

{

printf("%c ", (char)alphabet + j);

}

printf("\n");

}

}

### Pattern 28: Pyramid Alphabet Pattern

#include <stdio.h>

int main()

{

int i,j,rows=5;

int alphabet=64;

for (int i = 0; i <= 4; i++) {

int alphabet = 65; //ASCII value of “A”

for (int j = 4; j > i; j--) {

printf(" "); //Print Space

}

for (int k = 0; k <= i; k++) {

printf("%2c",(char) (alphabet + k)); //Print Alphabet

}

printf("\n");

}

}

Finally, look at some unique patterns using two symbols, a star and a hyphen.

#### Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN Stack

## Special Pattern

### Pattern 29: Half Diamond Pattern Using Star and Hyphen Symbol

#include<stdio.h>

void main(){

int i,j,k,rows=5;

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

{

if(i%2==0){

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

printf("-");

}

}else{

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

printf("*");

}

}

printf("\n");

}

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

{

if(i%2==0){

for(j=i;j>1;j--){

printf("*");

}

}

else{

for(j=i;j>1;j--){

printf("-");

}

}

printf("\n");

}

}

### Pattern 30: Left Half Diamond Pattern

#include<stdio.h>

void main(){

int i,j,k,rows=5;

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

{

for(j=0;j<rows-i;j++){

printf(" ");

}

if(i%2==0){

for(k=0;k<=i;k++){

printf("*");

}

}else{

for(k=0;k<=i;k++){

printf("-");

}

}

printf("\n");

}

for(i=rows-1;i>0;i--)

{

for(j=rows;j>=i;j--){

printf(" ");

}

if(i%2==0){

for(k=i;k>0;k--){

printf("-");

}

}else{

for(k=i;k>0;k--){

printf("*");

}

}

printf("\n");

}

}

### Pattern 31: Triangle Pattern

#include<stdio.h>

void main()

{

int i,j,rows=5,k;

for(i=0;i<rows;i++){

for(k=1;k<rows-i;k++){

printf(" ");

}

printf("*");

for(j=0;j<=i-1;j++){

printf("-");

}

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

printf("-");

}

if(i>0){

printf("*");

}

printf("\n");

}

### Pattern 32: Full Diamond

#include<stdio.h>

void main(){

int i,j,k,rows=5;

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

{

for(j=1;j<=rows-i;j++){

printf(" ");

}

if(i%2==1){

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

printf("*");

}

}else{

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

printf("-");

}

}

printf("\n");

}

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

{

for(j=rows;j>=i;j--){

printf(" ");

}

if(i%2==1){

for(k=2*i-2;k>1;k--){

printf("-");

}

}else{

for(k=2*i-2;k>1;k--){

printf("*");

}

}

printf("\n");

}

}

#### Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN Stack

### Pattern 33: Christmas Tree Pattern

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <time.h>

#define RefRate 20000

#define randomness 5

void clrscr()

{

system("@cls||clear");

}

// Print a random character giving preference

// to *

void printLeaf()

{

char ltypes[5] = { '*', '+', 'o', '.', 'O' };

int temp = rand() % randomness;

// Giving preference to *

if (temp == 1)

printf("%c ", ltypes[rand() % 5]);

else

printf("%c ", ltypes[1]);

}

void tri(int f, int n, int toth)

{

int i, j, k = 2 * toth - 2;

for (i = 0; i < f - 1; i++)

k--;

// number of rows

for (i = f - 1; i < n; i++) {

// space handler

for (j = 0; j < k; j++)

printf(" ");

// decrementing k after each loop

k = k - 1;

// number of columns, printing stars

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

printLeaf();

printf("\n");

}

}

// Prints multiple triangles

void printTree(int h)

{

int start = 1, stop = 0, diff = 3;

while (stop < h + 1) {

stop = start + diff;

tri(start, stop, h);

diff++;

start = stop - 2;

}

}

// Prints bottom part.

void displayLog(int n)

{

int i, j, k = 2 * n - 4;

for (i = 1; i <= 6; i++) {

// space handler

for (j = 0; j < k; j++)

printf(" ");

for (j = 1; j <= 6; j++)

printf("#");

printf("\n");

}

}

// Driver code

int main()

{

srand(time(NULL));

int t = 6;

printf("\n*********MERRY CHRISTMAS*********\n\n");

// refresh loop

while (1) {

clrscr();

printTree(t);

displayLog(t);

usleep(RefRate);

}

return 0;

}

## Next Steps

"C Interview Question" can be your next topic. So far, you have learned the C pattern programs. The following fundamentals will be the data structures and the varieties in data structures used for different purposes.

If you are interested in software development, you can explore Simplilearn's courses that will give you the work-ready software development training you need to succeed today. Are you looking for a comprehensive training program in today's most in-demand software development skills, tools, and languages? Our Full Stack Developer - MERN Stack should be the right thing for your career. Explore the course and enroll soon.

Please let us know in the comment section below if you have questions regarding the "C Pattern Programs ” tutorial. Our experts will get back to you at the earliest.

## FAQs

### 1. What are pattern programs in C?

Pattern programs in C involve using nested loops to print various patterns of characters, numbers, or symbols. These programs help understand the use of loops and conditional statements, which are fundamental concepts in programming. Examples include star patterns, number patterns, and alphabet patterns.

### 2. How do I write a simple star pattern program in C?

You need to use nested loops to write a simple star pattern program in C. Here’s an example of a basic right-angled triangle star pattern:

``````#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;
}
``````

This program prompts the user to enter the number of rows and prints a right-angled triangle of stars.

### 3. What are some common mistakes to avoid when writing pattern programs in C?

Incorrect loop boundaries: Ensure that loop counters are correctly set to start and end at the right values.

Not using nested loops properly: Understand the structure of nested loops to print the correct pattern.

Ignoring edge cases: Consider and handle cases like zero or negative input values.

Misplacing print statements: Ensure that printf statements are correctly placed within the loops to format the output correctly.

### 4. How can I print a pyramid number pattern in C?

To print a pyramid number pattern, you need to handle spaces and numbers properly in the nested loops. Here’s an example:

``````#include <stdio.h>

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

### 5. Where can I find more practice problems for pattern programs in C?

You can find more practice problems on educational websites like GeeksforGeeks, HackerRank, and LeetCode. Additionally, many programming textbooks and online courses include sections on pattern programs. Joining programming forums and communities can also provide access to a wealth of shared problems and solutions.