C program to print Hut star pattern

  • Write a C program to print a Hut star pattern.
Hut star pattern program's output should be:
C program print hut star pattern

Required Knowledge

Algorithm to print hut star pattern
Printing a hut star pattern is a two step process.
  • Step 1: Print pyramid star pattern for top 5 rows. Check this c program to print pyramid star pattern.
  • Step 2: Print the bottom half of the hut. Each row of the bottom half of hut contains 3 stars then three space characters followed by 3 stars.

Here is the matrix representation of the Hut star pattern. The row numbers are represented by i whereas column numbers are represented by j.

C program print hut star pattern

C program to print Hut star pattern on screen

#include<stdio.h>

int main() {
    int i, j, space, rows = 8, star = 0;

    /* Printing upper triangle */
    for (i = 0; i < rows; i++) {
        if (i < 5) {
            /* Printing upper triangle */
            for (space = 1; space < 5 - i; space++) {
                printf(" ");
            }
            /* Printing stars */
            while (star != (2 * i + 1)) {
                printf("*");
                star++;;
            }
            star = 0;
            /* move to next row */
            printf("\n");
        } else {
            /* Printing bottom walls of huts */
            for (j = 0; j < 9; j++) {
                if ((int) (j / 3) == 1)
                    printf(" ");
                else
                    printf("*");
            }
            printf("\n");
        }
    }
    return 0;
}
Output
    *
   ***
  *****
 *******
*********
***   ***
***   ***
***   ***

Related Topics
C program heart star pattern
C program diamond star pattern
C program rhombus star pattern
C program rectangle star pattern
C program pyramid star pattern
C program multiplication table triangle pattern
C program exponentially increasing star pattern
C program palindrome triangle pattern
C program binary triangle pattern
List of all C pattern programs