Here is C# version:
using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int a, b, c, num;
int d = 1;
Console.WriteLine("Enter the number: ");
/*
There are couple ways to convert input from the console to integer,
you can use them all but in this example I think the best will be second method
*/
/* 1. Parse --------------------------------------------------------------------------
this will throw exception if user writes to console value of different type than integer
if you can, try to avoid exceptions
-------------------------------------------------------------------------- */
/*
try
{
num = Int32.Parse(Console.ReadLine());
}
catch (FormatException)
{
Console.WriteLine("Error method 1, entered value must be of integer type !");
}
*/
/* 2. TryParse --------------------------------------------------------------------------
This tests if writed value is in correct format, if not it will return false
its cheaper and faster than using exceptions
-------------------------------------------------------------------------- */
bool test = Int32.TryParse(Console.ReadLine(), out num);
if (!test)
Console.WriteLine("Error method 2, entered value must be of integer type !");
/* 3. Convert --------------------------------------------------------------------------
in this example, like with Parse, if input value is not integer it will thto exception
-------------------------------------------------------------------------- */
/*
try
{
num = Convert.ToInt32(Console.ReadLine());
}
catch (FormatException)
{
Console.WriteLine("Error method 3, entered value must be of integer type !");
}
*/
for (c = num; c >= 1; c--)
{
for (a = c; a >= 1; a--)
Console.Write(" "); //cout<<" ";
if (d < num)
{
for (b = 1; b <= d; b++)
Console.Write("*" + " "); //cout<<"*"<<" ";
}
d++;
if (d != num)
Console.WriteLine(); //cout << endl;
}
d = 1;
for (c = num; c >= 1; c--)
{
for (b = 1; b <= d; b++)
{
Console.Write(" "); //cout << " ";
}
if (d <= num)
{
for (a = c; a >= 1; a--)
Console.Write("*" + " "); //cout << "*" << " ";
}
d++;
Console.WriteLine(); //cout << endl;
}
Console.ReadLine();
}
}
}