* * ** ** *** *** ******** *** *** ** ** * * Logic: Upper half and lower half symmetric. Carefully calculate the pattern of stars and spaces.
#include <stdio.h>
int main() {
int n = 4; // Half of the butterfly (number of rows in upper half)
// Upper half
for (int i = 1; i <= n; i++) {
// Left stars
for (int j = 1; j <= i; j++)
printf("*");
// Spaces
for (int j = 1; j <= 2*(n-i); j++)
printf(" ");
// Right stars
for (int j = 1; j <= i; j++)
printf("*");
printf("n");
}
// Lower half
for (int i = n-1; i >= 1; i--) {
// Left stars
for (int j = 1; j <= i; j++)
printf("*");
// Spaces
for (int j = 1; j <= 2*(n-i); j++)
printf(" ");
// Right stars
for (int j = 1; j <= i; j++)
printf("*");
printf("n");
}
return 0;
}
#include <stdio.h>
int main() {
int n = 4; // Half of the butterfly (number of rows in upper half)
// Upper half
for (int i = 1; i <= n; i++) {
// Left stars
for (int j = 1; j <= i; j++)
printf("*");
// Spaces
for (int j = 1; j <= 2*(n-i); j++)
printf(" ");
// Right stars
for (int j = 1; j <= i; j++)
printf("*");
printf("n");
}
// Lower half
for (int i = n-1; i >= 1; i--) {
// Left stars
for (int j = 1; j <= i; j++)
printf("*");
// Spaces
for (int j = 1; j <= 2*(n-i); j++)
printf(" ");
// Right stars
for (int j = 1; j <= i; j++)
printf("*");
printf("n");
}
return 0;
}