我想打印这个: 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--)