This is the program to display the diamond
shape using c#.
using System.Text;
class Program
{
static void Main(string[] args)
{
int tinggi;
int lebar = 1;
int spasi;
try
{
Console.Write("input an integer: ");
tinggi = Int32.Parse(Console.ReadLine());
}
catch(FormatException e)
{
tinggi = 5;
}
spasi = tinggi;
for (int i = 0; i < tinggi; i++)
{
int x = i;
if (tinggi % 2 == 1)
x++;
for (int j = 0; j < spasi; j++)
Console.Write(" ");
for (int k = 0; k < lebar; k++)
{
if(k==(lebar/2))
Console.Write("X");
else if (x % 2 == 0)
Console.Write("*");
else
Console.Write("o");
}
Console.Write("n");
spasi--;
lebar += 2;
}
for (int i = 0; i < tinggi; i++)
{
for (int j = 0; j < spasi; j++)
Console.Write(" ");
{
if (k == (lebar / 2))
Console.Write("X");
else if (i % 2 == 0)
Console.Write("*");
else
Console.Write("o");
}
}
spasi++;
}
for (int j = 0; j < spasi; j++)
Console.Write(" ");
}
}
}
using System;
using System.Collections.Generic;using System.Text;
namespace Emerald
{class Program
{
static void Main(string[] args)
{
int tinggi;
int lebar = 1;
int spasi;
try
{
Console.Write("input an integer: ");
tinggi = Int32.Parse(Console.ReadLine());
}
catch(FormatException e)
{
tinggi = 5;
}
spasi = tinggi;
for (int i = 0; i < tinggi; i++)
{
int x = i;
if (tinggi % 2 == 1)
x++;
for (int j = 0; j < spasi; j++)
Console.Write(" ");
for (int k = 0; k < lebar; k++)
{
if(k==(lebar/2))
Console.Write("X");
else if (x % 2 == 0)
Console.Write("*");
else
Console.Write("o");
}
Console.Write("n");
spasi--;
lebar += 2;
}
for (int i = 0; i < tinggi; i++)
{
for (int j = 0; j < spasi; j++)
Console.Write(" ");
for (int k =
0; k < lebar; k++)
{
if (i == 0)
Console.Write("X");
{
if (k == (lebar / 2))
Console.Write("X");
else if (i % 2 == 0)
Console.Write("*");
else
Console.Write("o");
}
}
Console.Write("n");
lebar -= 2;spasi++;
}
for (int j = 0; j < spasi; j++)
Console.Write(" ");
Console.Write("X");
Console.Read();}
}
}
Join the conversation! Your thoughts help the community grow.