列印菱形的神奇方法(簡短)
阿新 • • 發佈:2019-02-14
A
BCD
CDEFG
DEFGH I J
CDEFG
BCD
A
#include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> #include <windows.h> int main() { char m; int n,i,j; while(scanf("%d",&n)!=EOF){ n/=2; for(i=-n;i<=n;i++){ m='A'+n-abs(i); for(j=-n;j<=n;j++){ if(abs(i)+abs(j)<=n) putchar(m++); else if(j<0) putchar(' '); } putchar('\n'); } } }/////////神奇的菱形