使用任何编程语言的小屋程序 [英] Hut Program in any programming language

查看:131
本文介绍了使用任何编程语言的小屋程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来编写一个程序,在给定索引的情况下使用C#绘制小屋形状.索引可以大于4,并且只能为偶数.

下图是索引6的图:

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:

      *
    *   *
  *       *
* *       * *
  *       *
  * *   * *

推荐答案

有趣的是,我曾经喜欢用C语言编写的此类程序.很久以后就不要停止尝试了.

你可以用这样的东西做小屋,
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,
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

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


这篇关于使用任何编程语言的小屋程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆