C Program to print Hourglass Pattern for n number of lines.[Pattern 24]| Using C language| C Program series 45|
👨💻C Program to print Hourglass Pattern for n number of lines.[Pattern:24]
Code :
For n number of LINES:
/*
C Program to print Hourglass Pattern for n number of lines.[Pattern 24]
For Example:n=5
# # # # #
# # # #
# # #
# #
#
# #
# # #
# # # #
# # # # #
*/
#include<stdio.h>
main()
{
printf("C Program to print Hourglass Pattern for n number of lines.[Pattern 24]\n\n");
int i,j,n;
printf("Enter Center of Hourglass at line number:");
scanf("%d",&n);
printf("==> Hourglass Pattern.\n");
for(i=1;i<2*n;i++)
{
printf("\n%d\t",i);//here, '\t' used to shift pattern 1 tab space right side
if(i<=n)
{
for(j=1;j<i;j++)
{
printf(" ");
}
for(j=n-i+1;j>0;j--)
{
printf("# ");
}
}
else
{
for(j=2*n-1-i;j>0;j--)
{
printf(" ");
}
for(j=1;j<=(n-(2*n-1-i));j++)
{
printf("# ");
}
}
}
printf("\n");
}
The output of Code:

![C Program to print Hourglass Pattern for n number of lines.[Pattern 24]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6ptEQKt8bjfZ0ScEvePFNPSPYKH8Cz9iOTPQ710YZY1FLP_9qjelXFgDvajjxdv4xadHx7-V00f5F5YjJg23nwMKWvQ8B6ElS4e0q-eu9IwKlPFEKNZlmWAN0gy2vviMM5ecrl_8w_T350qsCmOeLY3QNqy8K0Qa1WQMloT2kFDzD0c_vVG5NNRI/w640-h298/Screenshot%202022-11-17%20163159.jpg)
![C Program to print Hourglass Pattern for n number of lines.[Pattern 24]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXq2loCX94XmTY1BPBLxsYzF0vlOUEHLZtDD8QUjOMr-1C06m8oyqMrr2r_0-zgjW2V4RF82HGyxNZnCB8e2h-5D2oshxGbeAeK9N1aG8xD-x0AiYfuZS8dmaUwbLZ0TwE4n9TmPcdtP73reGksnXEElX6j_9q4zL81Um8UPRquz5shl_KhPB8s1U/w640-h592/Screenshot%202022-11-17%20163220.jpg)
Comments
Post a Comment