不想起名字a 发表于 2021-3-11 01:48:23

那个 这个东西不会弄 求大佬帮一下

输入 n 值,输出高度为 n 的等腰三角形。例如当 n=5 时的图形如下:
*
***
*****
*******
*********
要求:用自定义函数 void print(int m)完成每一行图形的打印。

jackz007 发表于 2021-3-11 02:20:55

本帖最后由 jackz007 于 2021-3-11 02:22 编辑

def prt(m):
    for x in range(m):
      print(' ' * (m - x - 1) + '*' * (2 * x + 1))
prt(int(input()))
      运行实况
D:\00.Excise\Python>python x.py
15
            *
             ***
            *****
         *******
          *********
         ***********
      *************
       ***************
      *****************
   *******************
    *********************
   ***********************
*************************
***************************
*****************************

D:\00.Excise\Python>

my_angel 发表于 2021-3-11 02:46:49

这种大学课本题目,一百度就有解了。

baige 发表于 2021-3-11 06:32:46

#include <stdio.h>

char s;
int idx, n;

void print(int n){
        s = '*';
        for(int i = 1; i <= n; i++){
                printf("%s\n",s);
                s='*';
        }       
}

int main(void){
        scanf("%d",&n);
        print(n);
        return 0;
}

不想起名字a 发表于 2021-3-11 09:55:17

感谢感谢
页: [1]
查看完整版本: 那个 这个东西不会弄 求大佬帮一下