2/02/2012

C# Number Pattern (17)

C# Number Pattern (17)
C# Number Pattern (17)

 /* C# program to print the following pattern   
 1  
 2 4  
 1 3 5  
 2 4 6 8  
 1 3 5 7 9  */  
 namespace Patterns   
 {  
   class Program  
   {  
     static void Main(string[] args)  
     {  
       int i, j, k;  
       for (i = 1; i <= 5; i++)  
       {  
         if (i % 2 == 0)  
         {  
           k = 2;  
         }  
         else  
         {  
           k = 1;  
         }  
         for (j = 1; j <= i; j++, k += 2)  
         {  
           Console.Write(k);  
         }  
         Console.WriteLine();  
       }        
     }  
   }  
 }  

No comments:

Post a Comment