Click here to Skip to main content
15,917,473 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
namespace print_number_1_to_1000
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 1000; i=i+1)
            {
                Console.WriteLine(i);
            }


                Console.ReadLine();
        }
    }
}

but the problem is it only prints from 702 to 1000

what would be the code to print number from 1 to 1000
Posted
Updated 29-Sep-12 10:58am
v2

This will be your code...
C#
static void Main(string[] args)
{
    for (int i = 1; i <= 1000; i++)
    {
        Console.Write(i+" ");
    }
    Console.ReadLine();
}
 
Share this answer
 
Try the following:
C#
namespace print_number_1_to_1000
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.BufferHeight = 2000;

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


                Console.ReadLine();
        }
    }
}

See here for an explanation:
http://msdn.microsoft.com/en-us/library/system.console.bufferheight.aspx[^]
 
Share this answer
 
v2
Comments
Kuthuparakkal 29-Sep-12 17:15pm    
my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900