2/02/2012

C# Number Pattern (13)

C# Number Pattern (13)
C# Number Pattern (13)
 /* C# program to print the following pattern   
 12345  
 4321  
 123  
 21  
 1  */  
 namespace Patterns   
 {  
   class Program  
   {  
     static void Main(string[] args)  
     {  
       int i, j, k;  
       for (i = 5; i >= 1; i--)  
       {  
         if (i % 2 == 1) k = 1;  
         else k = i;  
         for (j = 1; j <= i; j++)  
         {  
           Console.Write(k);  
           if (i % 2 == 1) k++;  
           else k--;  
         }  
         Console.WriteLine();  
       }        
     }  
   }  
 }  

No comments:

Post a Comment