Saturday 22 November 2014

Star Pattern In C# - 1

Pyramid Star Pattern
Fig 1 : Pyramid Star Pattern


 using System;
class Test
{
public static void Main()
{
int i=1,j,row;
Console.WriteLine("Enter the no. of row: ");
row=Convert.ToInt32(Console.ReadLine());

for(i=1;i<=row;i++)
{
for(j=row-i;j>=1;j--)
Console.Write(" ");

for(j=1;j<=i;j++)
Console.Write("*");

for(int k=i-1;k>=1;k--)
Console.Write("*");
Console.WriteLine();
}
}
}

----------------------------------------OR----------------------------------------

using System;

class Pattern_1
{
public static void Main()
{
int row;
int n;
int temp;
int c;

Console.WriteLine("Enter the no. of row you want to print int the pyramid: ");
n=Convert.ToInt32(Console.ReadLine() );

temp=n;
for(row=1;row<=n;row++)
{
for(c=1;c<temp;c++)
Console.Write(" ");
temp--;

for(c=1;c<=2*row-1;c++)
Console.Write("*");


Console.WriteLine();
}
}
}