The pyramid height is to be supplied as well as the character used in building the pyramid.
I have equally ported the C++ program to C#
C++
# include
# include
void main()
{
int height;
char design;
cout<"enter pyramid height";
cin>>height;
cout<<"enter pyramid design";
cin>>design>>endl;
for (int i = 0; i < height; i++)
{
for (int k = i; k < height; k++)
{
cout<<" ";
}
for (int j = 2 * i + 1; j > 0; j--)
{
cout<< design
}
cout<<""<< endl
}
getch();
}
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Pyramid
{
class Program
{
static void Main(string[] args)
{
int height;
char design;
Console.Write("enter pyramid height ");
height = int.Parse(Console.ReadLine());
Console.WriteLine("");
Console.WriteLine("");
Console.Write("enter pyramid design ");
design = char.Parse(Console.ReadLine());
Console.WriteLine("");
Console.WriteLine("");
for (int i = 0; i < height; i++)
{
for (int k = i; k < height; k++)
{
Console.Write(" ");
}
for (int j = 2 * i + 1; j > 0; j--)
{
Console.Write(design);
}
Console.WriteLine("");
}
Console.ReadLine();
}
}
}
This is the program output after having supplied 30 as the pyramid height and 8 as the
pyramid design.