Click here to Skip to main content
15,885,130 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need help to write a program to draw a hut shape in C# , given an index. The index can be above 4 and only an even number.

The figure is that shown below for the index 6:
      *
    *   *
  *       *
* *       * *
  *       *
  * *   * *
Posted
Updated 22-Aug-11 18:56pm
v2
Comments
walterhevedeich 23-Aug-11 0:49am    
And what help do you need here?
Prerak Patel 23-Aug-11 0:54am    
Did you try anything? It is so simple I guess.

1 solution

Funnily, I used to love such * programs in C. I wouldn't have answered this, but I couldn't stop trying this after a long time.

You can make a hut with something like this,
VB
Dim inp As Integer = CInt(InputBox("Even Number > 4"))
Dim output(,) As String
ReDim output(inp - 1, inp)
For i As Integer = 1 To inp
  If i = 1 Then
    output(i - 1, inp / 2) = "*"
  ElseIf i > 1 And inp / 2 - i + 1 > 0 Then
    output(i - 1, inp / 2 - i + 1) = "*"
    output(i - 1, inp / 2 + i - 1) = "*"
  ElseIf inp / 2 - i + 1 = 0 Then
    output(i - 1, inp / 2 - i + 1) = "*"
    output(i - 1, inp / 2 - i + 2) = "*"
    output(i - 1, inp / 2 + i - 2) = "*"
    output(i - 1, inp / 2 + i - 1) = "*"
  ElseIf inp / 2 - i + 1 < 0 Then
    output(i - 1, 1) = "*"
    output(i - 1, inp - 1) = "*"
    If i = inp Then
      output(i - 1, 2) = "*"
      output(i - 1, inp - 2) = "*"
    End If
  End If
Next


and output like this
VB
Dim opstring As String = ""
For i As Integer = 0 To output.GetLength(0) - 1
  For j As Integer = 0 To output.GetLength(1) - 1
    If output(i, j) = "" Then
      opstring &= " "
    Else
      opstring &= "*"
    End If
  Next
  opstring &= vbCrLf
Next
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900