且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#如何在两个数字之间找到几个数字(简单)

更新时间:2023-02-10 09:46:51

我会做以下脚本。它更清晰可读。



I would do the following script. It is clearer and readable.

int i = 0;
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
for (i = a;i<b;i++)
{
   if (i % 2 == 0)
    {
         Console.WriteLine(i);
    }
               
}





希望有所帮助。


***的问候,



Carlos



Hope it helps.

best regards,

Carlos


开始我等于两者中的最小值并达到最大值:

Start with i equal to the minimum of the two and go up to the maximum of the pair:
int min = Math.Min(a, b);
int max = Math.Max(a, b);
i = min;
while (i < max)
   {
   ...
   i++;
   }