Creating Pyramid in C#
To using Console Application......
class :-- application.cs
------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationfirst
{
class Program
{
static void Main(string[] args)
{
fnpyramid obj = new fnpyramid();
obj.createPyramid();
Console.WriteLine("\n");
obj.createPyramidNumber();
Console.WriteLine("\n");
Console.WriteLine("Example made by DOTNET BY VICKYPEDIA");
Console.Read();
}
}
}
class :-- fnPyramid.cs
------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationfirst
{
class fnpyramid
{
/// <summary>
/// Create function for print pyramid like....
/// 1
/// 121
/// 12321
/// 1234321
/// 123454321
/// </summary>
public void createPyramid()
{
int numberoflayer = 6, Space, Number;
Console.WriteLine("Print paramid as Number");
for (int i = 1; i <= numberoflayer; i++)
{
for (Space = 1; Space <= (numberoflayer - i); Space++)
Console.Write(" ");
for (Number = 1; Number <= i; Number++)
Console.Write('*');
for (Number = (i - 1); Number >= 1; Number--)
Console.Write('*');
Console.WriteLine();
}
}
/// <summary>
/// Create function for print pyramid like....
/// *
/// ***
/// *****
/// *******
/// *********
/// </summary>
public void createPyramidNumber()
{
int numberoflayer = 6, Space, Number;
Console.WriteLine("Print paramid as Star");
// Total number of layer for pramid
for (int i = 1; i <= numberoflayer; i++)
{
// Loop For Space
for (Space = 1; Space <= (numberoflayer - i); Space++)
Console.Write(" ");
//increase the value
for (Number = 1; Number <= i; Number++)
Console.Write(Number);
//decrease the value
for (Number = (i - 1); Number >= 1; Number--)
Console.Write(Number);
Console.WriteLine();
}
}
}
}
OUTPUT
--------------------------------