Sunday 1 February 2015

Number Pattern in C# - 24

Question: Program to print the following pattern.


5
4 5
3 4 5
2 3 4 5
1 2 3 4 5

Code Snippet:

  1. using System;  
  2. public class pattern  
  3. {  
  4.     public static void Main()  
  5.     {  
  6.         int row, col, n;  
  7.   
  8.         Console.Write("Enter th eno. of row: ");  
  9.         n=Convert.ToInt32(Console.ReadLine());  
  10.         int temp=n;  
  11.   
  12.         for(row=1; row<=n; row++)  
  13.         {  
  14.               
  15.             for(col = temp; col<=n; col++)  
  16.               
  17.                 Console.Write("{0} ",col);  
  18.                 temp--;  
  19.               
  20.                 Console.WriteLine();  
  21.   
  22.               
  23.         }  
  24.   
  25.         Console.ReadLine();  
  26.     }  
  27. }  

Output of Number Pattern
Fig: Screenshot of output