Question: Program to print the following pattern.
9
0 1
2 3 4
5 6 7 8
9 0 1 2 3
Code Snippet:
- using System;
- public class pattern
- {
- public static void Main()
- {
- int row, col, i, n, x=0;
- Console.Write("Enter the no. of row: ");
- n=Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("9");
- for(row=2; row<=n; row++)
- {
- for(col = 1; col<=row; col++,x++)
- {
- if(x<10)
- Console.Write("{0} ",x);
- else
- {
- for(i=0; i<=3; i++)
- Console.Write("{0} ",i);
- break;
- }
- }
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- }
Fig: Screenshots of Output |