Question: Program to print following pattern.
54 5 4
3 4 5 4 3
2 3 4 5 4 3 2
1 2 3 4 5 4 3 2 1
Code Snippet:
using System; public class Pattern { public static void Main() { int i, j, n, temp, count; Console.Write("Enter the no. of row: "); n=Convert.ToInt32(Console.ReadLine()); temp=n; count=n; for(i=n; i>=1; i--) { for(j=1; j<temp; j++) Console.Write(" "); for(j=i; j<=count; j++) Console.Write("{0} ",j); for(j=count-1; j>=i; j--) Console.Write("{0} ",j); temp--; Console.WriteLine(); } Console.ReadLine(); } }
Fig: Screenshot of output |