Program that displays hour glass pattern.
Solution in C PYTHON
#include<stdio.h>
int main(){
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++){
for(j=1;j<i;j++)
printf(" ");
for(j=n-i+1;j>=1;j--){
printf("#");
if(j>1) printf(" ");
}
printf("\n");
}
for(i=n;i>=1;i--){
for(j=1;j<i;j++)
printf(" ");
for(j=n-i+1;j>=1;j--){
printf("#");
if(j>1) printf(" ");
}
printf("\n");
}
return 0;
}
int main(){
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++){
for(j=1;j<i;j++)
printf(" ");
for(j=n-i+1;j>=1;j--){
printf("#");
if(j>1) printf(" ");
}
printf("\n");
}
for(i=n;i>=1;i--){
for(j=1;j<i;j++)
printf(" ");
for(j=n-i+1;j>=1;j--){
printf("#");
if(j>1) printf(" ");
}
printf("\n");
}
return 0;
}
Input
7
Output
# # # # # # #
# # # # # #
# # # # #
# # # #
# # #
# #
#
#
# #
# # #
# # # #
# # # # #
# # # # # #
# # # # # # #
7
Output
# # # # # # #
# # # # # #
# # # # #
# # # #
# # #
# #
#
#
# #
# # #
# # # #
# # # # #
# # # # # #
# # # # # # #