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.
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
 }
}
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
 }
}
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
 }
}
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
}
}
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");
}
}
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");
}
}
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"); Â
    }       Â
}Â Â
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.
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");
    }
} Â
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 Post Graduate Program in Full Stack Web Development 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.