我想打印这个:-
1个
121
12321
1234321
123454321
这个程序打印这个。程序中可能有什么错误?在 for 循环中?请告诉我如何解决这个问题。我使用的逻辑有什么错误。如果是这样,我的逻辑有什么问题?在不久的将来我应该如何看待算法? :-
1个
12
123
123432
123454321
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a, b, c, d, e;
b = 6;
for(a=b;a>=1;a--)
{
for (c = a; c >=1; c--)
{
Console.Write(" ");
}
for(d=1; d<=b-a;d++)
{
Console.Write(d);
}
for (e = b-a-1; e>=a; e--)
{
Console.Write(e);
}
Console.WriteLine();
}
}
}
}
请告诉我代码中的问题。
最佳答案
问题出在行 for (e = b-a-1; e>=a; e--)
将其更改为简单的 for (e = b-a-1; e>=1; e--)
关于C# 打印 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26645707/