Program that displays butterfly pattern.
Sample Input5
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(col=1;col<=row;col++)
printf("*");
for(space=1;space<=2*(n-row);space++)
printf(" ");
for(col=1;col<=row;col++)
printf("*");
printf("\n");
}
for(row=n;row>=1;row--){
for(col=1;col<=row;col++)
printf("*");
for(space=1;space<=2*(n-row);space++)
printf(" ");
for(col=1;col<=row;col++)
printf("*");
printf("\n");
}
return 0;
}
int main() {
int n,row,col,space;
scanf("%d",&n);
for(row=1;row<=n;row++){
for(col=1;col<=row;col++)
printf("*");
for(space=1;space<=2*(n-row);space++)
printf(" ");
for(col=1;col<=row;col++)
printf("*");
printf("\n");
}
for(row=n;row>=1;row--){
for(col=1;col<=row;col++)
printf("*");
for(space=1;space<=2*(n-row);space++)
printf(" ");
for(col=1;col<=row;col++)
printf("*");
printf("\n");
}
return 0;
}
Input
5
Output
* *
** **
*** ***
**** ****
**********
**********
**** ****
*** ***
** **
* *
5
Output
* *
** **
*** ***
**** ****
**********
**********
**** ****
*** ***
** **
* *