Question: Program to print the following Pattern.
1
2 2 2
3 3 3 3 3
4 4 4 4 4 4 4
Code Snippet:
1
2 2 2
3 3 3 3 3
4 4 4 4 4 4 4
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());
- for(row=1; row<=n; row++)
- {
- for(col = 1; col<=n-row; col++)
- Console.Write(" ");
- for(col=1; col<=row; col++)
- Console.Write("{0} ", row);
- for(col=1;col<row; col++)
- Console.Write("{0} ", row);
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- }
Fig: Screenshot of the output |