通过循环输出图形
通过循环输出以下图形:*###*
*#*
*
*#*
*###*
/*------------------------------------------------------------------------------ *###* *#* * *#* *###* -------------------------------------------------------------------------------*/ #include<stdio.h> #include<math.h> int main(void) { int i,j,n; while(1) { printf("input n:\n"); scanf("%d",&n); if(n%2==0) printf("error\n"); else break; } for(i=-n;i<=n;i+=2) { for(j=0;j<(40-abs(i));j+=2) printf(" "); if(abs(i)==1) { printf("*\n"); i+=2; continue; } else { printf("*"); for(j=0;j<abs(i)-2;++j) printf("#"); printf("*"); } printf("\n"); } return 0; }
#include <stdio.h> int main(void) { int i,j,n; printf("input n:\n"); scanf("%d",&n); for(i=n;i>2;i-=2) { for(j=0;j<40-i;j+=2) printf(" "); printf("*"); for(j=0;j<i-2;++j) printf("#"); printf("*\n"); } for(i=0;i<20;++i) printf(" "); printf("*\n"); for(i=3;i<=n;i+=2) { for(j=0;j<40-i;j+=2) printf(" "); printf("*"); for(j=0;j<i-2;++j) printf("#"); printf("*\n"); } return 0; }