题解 | #牛牛的字符菱形# 通用算法,行数n任意
牛牛的字符菱形
http://www.nowcoder.com/practice/11a5040fa894430f9d25fda1be37ddc8
#include <stdio.h>
//注意-(x)一定要加括号,x可能是表达式,这个bug找了好久
#define ABS(x) ((x>=0)?x:-(x))
int main() {
char ch;
int n = 5;
scanf("%c", &ch);
for (int i = 0; i < n; i++) {
for (int j = 0; j < ABS(n / 2 - i); j++) {
printf(" ");
}
for (int j = 0; j < n - 2 * ABS(n / 2 - i); j++) {
printf("%c", ch);
}
for (int j = 0; j < ABS(n / 2 - i); j++) {
printf(" ");
}
printf("\n");
}
return 0;
}