for (i=1; i<=4; i++) { for (j=3;j>=i;j--) printf(" "); printf("*"); for (k=1; k<=(i-1)*2-1; k++) printf(" "); if (i != 1) printf("*"); printf("\n"); } for (i=3; i>=1; i--) { for (j=3; j>=i; j--) printf(" "); printf("*"); for (k=1; k<=(i-1)*2-1; k++) printf(" "); if (i != 1) printf("*"); printf("\n"); }
}
#include <stdio.h>
void main()
{ int i,j,k,n; printf("输入奇数:"); scanf("%d",&n);
for (i=1; i<=n; i++) { for (j=n-1;j>=i;j--) printf(" "); printf("*"); for (k=1; k<=(i-1)*2-1; k++) printf(" "); if (i != 1) printf("*"); printf("\n"); } for (i=n-1; i>=1; i--) { for (j=n-1; j>=i; j--) printf(" "); printf("*"); for (k=1; k<=(i-1)*2-1; k++) printf(" "); if (i != 1) printf("*"); printf("\n"); }
}
把三楼的改了一下,希望是你想要的