PRINT BUTTERFLY PATTERN USING C#
using System;
public class Test
{
public static void Main()
{
var no = Console.ReadLine();
int n = Convert.ToInt32(no);
Pattern print = new Pattern();
print.Butterfly(n);
}
}
public class Pattern
{
public void Butterfly(int n)
{
int totalNoofStars = n*2;
int lefttriangle = 1;
int righttriangle = totalNoofStars;
for(int i=1;i<=totalNoofStars;i++)
{
if(i<=n)
{
lefttriangle++;
righttriangle--;
}
else
{
if(i==n+1)
{
lefttriangle= lefttriangle;
righttriangle = righttriangle;
}
else
{
lefttriangle--;
righttriangle++;
}
}
for(int j=1;j<=totalNoofStars;j++)
{
if(j<lefttriangle || j> righttriangle)
{
Console.Write("*");
}
else
{
Console.Write(" ");
}
}
Console.WriteLine();
}
}
}
public class Test
{
public static void Main()
{
var no = Console.ReadLine();
int n = Convert.ToInt32(no);
Pattern print = new Pattern();
print.Butterfly(n);
}
}
public class Pattern
{
public void Butterfly(int n)
{
int totalNoofStars = n*2;
int lefttriangle = 1;
int righttriangle = totalNoofStars;
for(int i=1;i<=totalNoofStars;i++)
{
if(i<=n)
{
lefttriangle++;
righttriangle--;
}
else
{
if(i==n+1)
{
lefttriangle= lefttriangle;
righttriangle = righttriangle;
}
else
{
lefttriangle--;
righttriangle++;
}
}
for(int j=1;j<=totalNoofStars;j++)
{
if(j<lefttriangle || j> righttriangle)
{
Console.Write("*");
}
else
{
Console.Write(" ");
}
}
Console.WriteLine();
}
}
}
Comments
Post a Comment