【图形打印】菱形
/* 输入菱形的高度n(只能为奇数),输出图形 2014-4-1 18:38:57 */ #include <stdio.h> #include <stdlib.h> int main(){ int n, i, j, cen; char ch[2]; do{ printf("请输入菱形的高度:"); scanf("%d", &n); if(n % 2 == 0){ printf("Sorry, 菱形的高度只能是奇数。请重新来过。\n"); continue; } for(i = 1, cen = n / 2 + 1; i <= n; ++i){ for(j = 1; j <= n; ++j){ if(abs(i - cen) + abs(j - cen) <= cen - 1) putchar('*'); else putchar(' '); } putchar('\n'); } printf("继续吗?'y' or 'n':"); scanf("%s", ch); }while(ch[0] == 'y' || ch[0] == 'Y'); return 0; }