hut pattern program in c programming language

Hut pattern program in c programming language

Social Shares
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Hello readers, today you are going to learn how to print hut pattern program in c programming language. Before start print diamond pattern we need to know how looping statement works because looping statements like for loop or while loop plays a very important role to make a pattern program in c. If you have good knowledge of looping statements in c language then you can go with this session. So let’s get started.

Watch the full video for hut pattern program in c programming language

 

Explanation of  hut pattern program in c programming language


#include<stdio.h>
#include<conio.h>
void main() {
int i, j, space, rows=10, star=0;
clrscr();
/* 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");
}
}
getch();
}

 

The result of hut pattern program in c programming language

hut pattern program in c programming language

 

 

 

 

 

I hope you understand how to print diamond pattern program in c. If you understand then please share my hard work with your friends. Subscribe my newsletter for upcoming article’s updates direct in your mailbox. If you have any confusion or query then you can leave a message on my facebook page. At last, I would like to say please don’t forget to subscribe to my youtube channel. Thank you for visiting.


Social Shares
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply

Your email address will not be published. Required fields are marked *