Making pyramid using c#

后端 未结 13 2073
花落未央
花落未央 2021-01-03 11:04

My question is how to make a pyramid using * and \'space\' in C#? The output will be like this.

     *
    * *
   * * *
  * * * *
 * * * * *
<
13条回答
  •  攒了一身酷
    2021-01-03 11:31

    I know it's javascript but might help

    let n = 6;
    for (let i = 1; i <= n; i++) {
      let spaces = n-i;
      let str = '';
      for (let j=0; j < spaces; j++) {
        str+=' ';
      }
      
      for (let j=0; j < i; j++) {
        str+='* ';
      }
      console.log(str)
    }
    
    

提交回复
热议问题