Printing numbers from 1 to 1000 in console application in C#

妖精的绣舞 提交于 2019-12-11 06:57:02

问题


The problem is it only prints from 702 to 1000. What should be the code to print number from 1 to 1000.

static void Main(string[] args)
        {
            //    Console.Write("\tOutput : " + arr[0] + arr[1] + arr[2] + arr[3] + "\n");
            //int[] arr = new int[4] { 0, 0, 0, 0 };


            for (int i=0; i<=1000; i++)
            {
                Console.WriteLine(i);
            }
            Console.ReadKey();
        }

回答1:


You only see the last 300 or so lines because your console window has a limited line buffer.

Your code is fine (besides that it also prints 0) as you will see when you increase the line buffer size or redirect stdout to a file like so:

myprogram.exe > output.log



来源:https://stackoverflow.com/questions/42152380/printing-numbers-from-1-to-1000-in-console-application-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!