Author: admin

  • C Program to print Half Hourglass Star pattern

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

    1. Right half hourglass pattern in C

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

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


    2. Left half 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:

    java half hourglass pattern

  • Half Diamond Star Pattern in C

    We will write two different patterns diamond shape programs in C. So you may go through the following topic in C first.

    1. Right half diamond pattern in C

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

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


    2. Left half diamond 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 <= i; k++)
          printf("*");
    
        printf("\n");
      }
    
      for (i = rows; i >= 1; i--)
      {
        for (j = i; j <= rows; j++)
          printf(" ");
    
        for (k = 1; k < i; k++)
          printf("*");
    
        printf("\n");
      }
    
      return 0;
    }
    Enter the no. of rows: 5
        *
       **
      ***
     ****
    *****
     ****
      ***
       **
        *

  • Full Pyramid Pattern Program in C using Stars

    In this tutorial, we will write two different pyramid pattern programs using stars in C. Before that, you may go through the following topic in C.

    1. Full Pyramid Pattern Program in C

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

    2. Inverted full pyramid using * in C

    Inverted full Pyramid pattern in C.

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

  • Half Pyramid Star Pattern in C

    In this tutorial, we will write a program to display half pyramid patterns in C programming language. We will create a star pattern in C using for loop. So you may go through the following topic in C.


    1. Right half pyramid in C

    Right angle triangle pattern in C.

    #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 <= i; ++j)
        {
          printf("* ");
        }
    
        printf("\n");
      }
    
      return 0;
    }

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


    2. Left half pyramid in C

    Left right angle 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 = 1; j <= rows - i; j++)
          printf(" ");
    
        for (k = 1; k <= i; k++)
          printf("*");
    
        printf("\n");
      }
    
      return 0;
    }

    Output:

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

    3. Inverted right half pyramid pattern in C

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

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


    4. Inverted left half pyramid pattern in C

    #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++)
        {
          if (j < i)
            printf(" ");
          else
            printf("*");
        }
    
        printf("\n");
      }
    
      return 0;
    }

    Output:

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

  • 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