【问题标题】:Data Structure pseudo code数据结构伪代码
【发布时间】:2016-11-17 12:18:41
【问题描述】:

编写伪代码以打印星号菱形,如下所示。代码应提示 一个整数值,将用作图形中间的星号数 具有钻石的外观。它应该打印图形。示例:菱形宽度 --> 5

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

【问题讨论】:

  • stck 溢出不是代码生成器
  • 好吧,写吧。

标签: data-structures pseudocode


【解决方案1】:
    *
  * * *
* * * * *
  * * *
    *

要获得这样的输出:

for(int i = 0; i <= n/2; i++){
    for(int j = 0; j < n/2-i; j++){
        cout << " ";
    }
    for(int j = 0; j < 2*i+1; j++){
        cout << "*";
    }
    for(int j = 0; j < n/2-i; j++){
        cout << " ";
    }
    cout << endl;
}
for(int i = 0; i <= n/2; i++){
    for(int j = 0; j <= i; j++){
        cout << " ";
    }
    for(int j = 0; j < n-2*i-2; j++){
        cout << "*";
    }
    for(int j = 0; j <= i; j++){
        cout << " ";
    }
    cout << endl;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    相关资源
    最近更新 更多