Number Pattern Program in C#


Prev Tutorial Next Tutorial

Print Number Pattern Program in C#

In C# this code is very simple to write just follow same concept like C and C++ programming only you need to change syntax.

print number pattern in c#

Print Number Pattern Program in C#

using System;  

public class NumberPattern  
 {  
  public static void Main()
  {
  int no = 5;
   for (int i = 1; i <= 5; i++)
  {
   for (int j = 1; j <= i; j++)
  {
  Console.Write(i);
  }
  Console.WriteLine();
  }
  Console.ReadKey();  
 }
}

Output

1
22
333
4444
55555

Print Number Pattern Program in C#

using System;  

public class NumberPattern  
 {  
 public static void Main(string[] args)
 {
  int i, j, rows, k = 1;
  Console.Write("Enter number of rows: ");
  rows = Convert.ToInt32(Console.ReadLine());
  for (i = 1; i <= rows; i++)
   {
   for (j = 1; j <= i; j++)
   Console.Write("{0} ", k++);
   Console.Write("\n");
  }  
 }
}

Output

Enter number of rows: 4
1
2 3
4 5 6
7 8 9 10

Print Number Pattern Program in C#

using System;  

public class NumberPattern  
 {  
  public static void Main(string[] args)  
   {  
   int  i,j,k,l,n;           
   Console.Write("Enter the Range: ");    
    n= int.Parse(Console.ReadLine());     
    for(i=1; i<=n; i++)      
    {          
     for(j=1; j<=n-i; j++)      
     {      
     Console.Write(" ");      
     }      
     for(k=1;k<=i;k++)      
     {      
     Console.Write(k);      
     }      
     for(l=i-1;l>=1;l--)      
     {      
     Console.Write(l);      
     }      
     Console.Write("\n");      
     }       
  }  
 } 

Output

Enter the Range: 4
      1
    121
  12321
1234321

Output

Enter the Range: 5
        1
      121
    12321
  1234321
123454321  

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements