Question: Program to print the following Number Pattern?
01
02 04
03 06 09
04 08 12 16
05 10 15 20 25
Code Snippet:
- using System;
- public class Pattern
- {
- public static void Main()
- {
- int row, col, n, pr;
- Console.Write("Enter the no. of row: ");
- n = Convert.ToInt32(Console.ReadLine());
- for(row = 1; row <= n; row++)
- {
- pr = 0;
- for(col = 1; col <= row; col++)
- {
- pr = row*col;
- Console.Write("{0:D2} ", pr); // convert 1 to 01
- }
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- }
Fig: Screenshot of output |