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