Printing numbers from 1 to 1000 in console applica

2019-07-25 15:18发布

问题:

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