Sunday 1 February 2015

Number Pattern in C# - 23

Question: Program to print the following Pattern.


9
8 9 8
7 8 9 8 7
6 7 8 9 8 7 6

Code Snippet:

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


Output of number pattern
Fig: Screenshot of output