Question: Program to print the following pattern.
1234554321
1234__4321
123____321
12______21
1________1
Code Snippet:
- using System;
- public class Pattern
- {
- public static void Main()
- {
- int row,col,n;
- Console.Write("Enter the no. of row: ");
- n=Convert.ToInt32(Console.ReadLine());
- int temp=n;
- for(row=1; row<=n; row++)
- {
- for(col = 1; col<=temp; col++)
- Console.Write("{0}", col);
- for(col=1; col<row; col++)
- Console.Write("__");
- for(col=temp; col>=1; col--)
- Console.Write("{0}",col);
- temp--;
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- }
Fig: Screenshot of Output |