Friday, March 22, 2013

C#: Write a program to print to the screen the numbers from 1 to 6 (basic)


//RequirementsWrite a program to print to the screen the numbers from 1 to 6 as follows:
1                                                
12                                              
123                                            
1234                                          
12345                                        
123456

//Code:
class Program{
        static void Main()
        {
            for (int i = 1; i < 7; i++) {
                for (int j = 1; j <= i; j++)
                    Console.Write(j);
                    Console.WriteLine();
            }
            Console.ReadLine();

        }
}

No comments:

Post a Comment