Blog

  • C Program to Print Pyramid Pattern of Alphabets

    In this tutorial, we will learn and code many alphabet patterns in C programming language. However, in this tutorial, we will create a pyramid pattern using characters in C using for loop. So you may go through the following topic in C.


    C Alphabet Pattern program 1: Full Pyramid Pattern of Alphabets

    Enter the no. of rows: 5
         A 
       A B 
      A B C 
     A B C D 
    A B C D E 

    Source Code:

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j, k;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      // ASCII value of alphabet 'A'
      int alphabet = 65;
    
      for (i = 0; i <= rows - 1; i++)
      {
        for (j = rows - 1; j > i; j--)
          printf(" ");
    
        for (k = 0; k <= i; k++)
          printf("%c ", (char)(alphabet + k));
    
        printf("\n");
      }
    
      getch();
    }

    C Alphabet Pattern program 2: Inverted Full Pyramid Pattern of Alphabets

    Enter the no. of rows: 5
     A B C D E 
      A B C D 
       A B C 
        A B 
         A

    Source Code:

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j, k;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      // ASCII value of alphabet 'A'
      int alphabet = 65;
    
      for (i = 0; i <= rows - 1; i++)
      {
        for (int j = 0; j <= i; j++)
          printf(" ");
    
        for (k = 0; k <= rows - 1 - i; k++)
          printf("%c ", (char)(alphabet + k));
    
        printf("\n");
      }
    
      getch();
    }

    C Alphabet Pattern program 4:

    Another full pyramid with a different pattern.

    Enter the no. of rows: 5
           A
          B B
        C C C
       D D D D
      E E E E E
     F F F F F F

    Source Code:

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j, k;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      // ASCII value of alphabet 'A'
      int alphabet = 65;
    
      for (i = 0; i <= rows; i++)
      {
        for (j = 1; j <= rows - i; j++)
          printf(" ");
    
        for (k = 0; k <= i; k++)
          printf(" %c", (char)(i + alphabet));
    
        printf("\n");
      }
    
      getch();
    }

    C Alphabet Pattern program 5:

    Enter the no. of rows: 5
    A
    B A B
    C B A B C
    D C B A B C D
    E D C B A B C D E

    Source Code:

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

    C Alphabet Pattern program 6:

    Enter the no. of rows: 6
    A
    ABA
    ABCBA
    ABCDCBA
    ABCDEDCBA
    ABCDEFEDCBA

    Source Code:

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

    C Alphabet Pattern program 7:

    Enter the no. of rows: 5
    A B C D E F G H I
    A B C D E F G
    A B C D E
    A B C
    A

    Source Code:

    #include <stdio.h>
    
    void main()
    {
       int rows, i, j, l = 1, k;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = rows; i >= 1; i--)
       {
          for (j = 1; j <= l; j++)
             printf("  ");
    
          for (k = 1; k <= (2 *i - 1); k++)
             printf("%c ", 'A' + k - 1);
    
          l++;
          printf("\n");
       }
    }

    C Alphabet Pattern program 8: Inverted Pyramid pattern using while loop

    Enter the no. of rows: 5
    A B C D E D C B A
    A B C D C B A
    A B C B A
    A B A
    A

    Source Code:

    #include <stdio.h>
    
    void main()
    {
       int rows, i, j, l = 1, k;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       i = rows;
       while (i >= 1)
       {
          j = 1;
          while (j <= rows - i)
          {
             printf("  ");
             j++;
          }
    
          j = 1;
          while (j <= 2 *i - 1)
          {
             if (j <= i)
             {
                printf("%c", (char)(j + 64));
                printf(" ");
             }
             else
             {
                printf("%c", (char)(2 *i - j + 64));
                printf(" ");
             }
             j++;
          }
    
          i--;
          printf("\n");
       }
    }

  • Rectangle Star Pattern in C

    In this tutorial, we will write a C program to print a rectangular star pattern. You may go through the following topic on C first.

    Rectangle Star Pattern in C

    The program asks for the number of rows and columns that a user wants and prints the result.

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

    Enter number of rows: 4
    Enter number of columns: 7
    * * * * * * *
    * * * * * * *
    * * * * * * *
    * * * * * * *


  • Square Pattern of any Character in C

    In this tutorial, we will write a C program to print a square pattern of any characters. Before that, you may go through the following topics in C.

    Square pattern of character in C

    The program simply asks the user to enter the character that you want to print and the side of a square that is to be printed. And using that information inside a for loop, it prints the result.

    #include <stdio.h>
    
    int main()
    {
      int i, j, rows;
      char ch;
    
      printf("Enter the character you want to print: ");
      scanf("%c", &ch);
    
      printf("Enter the side of a Square: ");
      scanf("%d", &rows);
    
      for (i = 1; i <= rows; i++)
      {
        for (j = 1; j <= rows; j++)
          printf("%c ", ch);
    
        printf("\n");
      }
    
      return 0;
    }

    Output:

    Enter the character you want to print: $
    Enter the side of a Square: 5
    $ $ $ $ $
    $ $ $ $ $
    $ $ $ $ $
    $ $ $ $ $
    $ $ $ $ $


  • Square Star pattern in C

    In this tutorial, we will write a C program to print a square star pattern. Before that, you may go through the following topics in C.

    Square Star pattern in C

    The program takes the user input for the number of rows and uses that in a for loop.

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

    Output:

    Enter the no. of rows: 5
    * * * * *
    * * * * *
    * * * * *
    * * * * *
    * * * * *


  • Full hourglass pattern of Alphabets in C

    In this tutorial, we will write a C program to print an hourglass pattern using characters. Before that, you may go through the following topic in C.

    Full hourglass pattern of Alphabets in C

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j, k;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      // ASCII value of alphabet 'A'
      int alphabet = 65;
    
      for (i = 0; i <= rows - 1; i++)
      {
        for (j = 0; j < i; j++)
          printf(" ");
    
        for (k = i; k <= rows - 1; k++)
          printf("%c ", (char)(alphabet + k));
    
        printf("\n");
      }
    
      for (i = rows - 1; i >= 0; i--)
      {
        for (j = 0; j < i; j++)
          printf(" ");
    
        for (k = i; k <= rows - 1; k++)
          printf("%c ", (char)(alphabet + k));
    
        printf("\n");
      }
    
      getch();
    }

    Output:

    Enter the no. of rows: 5
    A B C D E
    B C D E
    C D E
    D E
    E
    E
    D E
    C D E
    B C D E
    A B C D E


  • Half Hourglass Alphabet Pattern in C

    In this tutorial, we will write a C program to print half hourglass pattern of characters. Before that, you may go through the following topic in C.

    We will go through the two different half hourglass of alphabets with two different character patterns.

    Half Hourglass Alphabet Pattern in C

    Pattern 1

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      //upper part
      for (i = rows; i >= 0; i--)
      {
        int character = 65;
        for (j = 0; j <= i; j++)
          printf("%c ", (char)(character + j));
    
        printf("\n");
      }
    
      //lower part
      for (i = 0; i <= rows; i++)
      {
        int character = 65;
        for (j = 0; j <= i; j++)
          printf("%c ", (char)(character + j));
    
        printf("\n");
      }
    
      getch();
    }

    Output:

    Enter the no. of rows: 5
    A B C D E F
    A B C D E
    A B C D
    A B C
    A B
    A
    A
    A B
    A B C
    A B C D
    A B C D E
    A B C D E F


    Pattern 2

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      //upper part
      for (i = rows; i >= 0; i--)
      {
        int character = 65;
        for (j = i; j >= 0; j--)
          printf("%c ", (char)(character + j));
    
        printf("\n");
      }
    
      //lower part
      for (i = 0; i <= rows; i++)
      {
        int character = 65;
        for (j = i; j >= 0; j--)
          printf("%c ", (char)(character + j));
    
        printf("\n");
      }
    
      getch();
    }

    Output:

    Enter the no. of rows: 5
    F E D C B A
    E D C B A
    D C B A
    C B A
    B A
    A
    A
    B A
    C B A
    D C B A
    E D C B A
    F E D C B A


  • C Program to print Odd Number Pattern

    In this tutorial, we will learn how to print odd number patterns in C. Before that, you may go through the following topic in C.

    The program takes a user input for the number of rows and prints the number pattern of the pyramid for odd numbers in C.

    C Program to print Odd Number Pattern

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

    Output:

    c program to print odd number pattern
  • C Program to print Floyd’s Triangle

    In this tutorial, we will write Floyd’s triangle pattern program in C. Before that, you should have knowledge on the following topic in C.


    Floyd’s Triangle in C

    #include <stdio.h>
    
    void main()
    {
      int i, j, k = 1, rows;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      printf("Floyd's Triangle:\n");
      for (i = 1; i <= rows; i++)
      {
        for (j = 1; j <= i; j++, k++)
        {
          printf("%2d ", k);
        }
    
        printf("\n");
      }
    
      getch();
    }

    Output:

    Floyd's Triangle pattern in C

  • Hollow Triangle Star Pattern in C

    In this tutorial, we will write a C program to print a hollow triangle star pattern. Before that, you may go through the following topics in C.

    Hollow Triangle Pattern in C

    Hollow equilateral triangle pattern in C.

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

    Output:


  • Hourglass Star Pattern in C

    In this tutorial, we will write a C program to print Full sandglass star patterns. Before that, you may go through the following topic in C.

    The program below takes a user input for the number of rows needed and then in decreasing order of the upper half is printed and then increasing the order, the second half sandglass is printed.

    This is a full hourglass pattern program in C or you can say full sandglass pattern program using a star.

    Full Hourglass Pattern in C

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

    Output:

    Enter the number of rows: 5
    * * * * * 
     * * * *
      * * *
       * *
        *
        *
       * * 
      * * *
     * * * * 
    * * * * *