C program to print Hut star pattern

  • Write a program in C to print a Hut star pattern.
  • How to draw a Hut on screen using star characters in C.
Hut star pattern program's output should be:
    *
   ***
  *****
 *******
*********
***   ***
***   ***
***   ***

Required Knowledge

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 = 1; 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