作业帮 > 综合 > 作业

求大神用C#的for语句编写个图形,样子如下:

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/29 12:20:13
求大神用C#的for语句编写个图形,样子如下:
1
121
12321
1234321
12321
121
1

跪求了 谢谢
如果能输入数字 让他变大小的最好了 不行就做死的 再次感谢
int x = 4;
for (int i = 0; i < 2 * x - 1; i++){
if (i < x) {
int y = 1;
for (int j = 0; j < 2 * x - 1; j++) {
if (y > 0) {
if (j < (x - i - 1)) {
Console.Write(" "); }
if (j >= (x - i - 1) && j < x - 1) {
Console.Write(y++); }
if (j >= x - 1) {
Console.Write(y--); } }
else {
Console.Write(" ");} }
Console.Write("\n");}
else {
int y = 1;
for (int j = 0; j < 2 * x - 1; j++){
if (y > 0){
if (j < (i - x + 1)) {
Console.Write(" "); }
if (j >= (i - x + 1) && j < x-1) {
Console.Write(y++); }
if (j >= x-1) {
Console.Write(y--);}}
else {
Console.Write(" ");} }
Console.Write("\n"); }}