(C#) Diamond Shape

Posted: July 30, 2008 in C#, Programming
Tags: ,


I’m still newbie in C#, i have installed Visual Studio for 1 month. I wrote a stupid code, he he he :) :) :) , i name my program “diamond shape”, here the input and output:



here the code:

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"); else { 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(); } } } [/sourcecode]

Comments
  1. crhistian says:

    heey great code… but your variables are unclear…I think it would be helpful to everyone if you coul put meaningful names to your variables…for example instead of tinggi use something more meaningful…I’m don’t know if that is a row or a column…But other than that thanks..the code works fine…

  2. azer89 says:

    thanks…
    but ya know..i wrote that variables name in Indonesian

  3. areklewong says:

    awas ngko mbayar lisensi…..

  4. azer89 says:

    lisensi opo mas????
    neng ndi???

  5. shyakaster says:

    Your code saved my day but I need to figure out how you named your variables..Thanks alot

  6. shyakaster says:

    what does lebar mean..?

  7. shyakaster says:

    Could you please do abit of explaining with documentation on how the code works..Thanks alot

  8. Ifti says:

    Its nice man…..

    I like it………..

    It shows you may be a good developer in future………..

  9. misugijunz says:

    hi azer89….

    ramein thread programmernya spmb-lover dong :D hehehe…

  10. jamie says:

    dont underestimate your self..
    this code quite nice for a beginner

  11. olivia says:

    the code is kwl man bt its a bit complicated plz try to mske it a bit easier

  12. AlexenderGr8 says:

    Hey man… nice code….
    but i would suggest u… first read lots of code available on net then try on ur own…
    as it u learn better and quickly from other experience…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s