Program that displays Hollow diamond in rectangle.
Sample Input7
Sample Output
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******
Solution in | C | JAVA | PYTHON |
---|
#include<stdio.h>
int main() {
int n, row, col;
scanf("%d",&n);
for(row=1;row<=n;row++){
for(col=1;col<=n-row+1;col++)
printf("*");
printf("%*c",2*row-1,' ');
for(col=1;col<=n-row+1;col++)
printf("*");
printf("\n");
}
for(row=n;row>=1;row--){
for(col=1;col<=n-row+1;col++)
printf("*");
printf("%*c",2*row-1,' ');
for(col=1;col<=n-row+1;col++)
printf("*");
printf("\n");
}
return 0;
}
int main() {
int n, row, col;
scanf("%d",&n);
for(row=1;row<=n;row++){
for(col=1;col<=n-row+1;col++)
printf("*");
printf("%*c",2*row-1,' ');
for(col=1;col<=n-row+1;col++)
printf("*");
printf("\n");
}
for(row=n;row>=1;row--){
for(col=1;col<=n-row+1;col++)
printf("*");
printf("%*c",2*row-1,' ');
for(col=1;col<=n-row+1;col++)
printf("*");
printf("\n");
}
return 0;
}
Input
7
Output
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******
7
Output
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******