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