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:
- using System;
- public class Pattern
- {
- public static void Main()
- {
- int row, col, n, temp=9,count;
- Console.Write("Enter the no. of row: ");
- n=Convert.ToInt32(Console.ReadLine());
- count=temp;
- for(row = 1; row<=n; row++)
- {
- for(col = count; col<=temp; col++)
- Console.Write("{0} ",col);
- for(col=temp-1; col>=count; col--)
- Console.Write("{0} ",col);
- count--;
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- }
Fig: Screenshot of output |