1
weifengzi2009 2018-11-22 20:21:38 +08:00
你这个 level 函数递归每次都乘以 2,那不是 2*2*2*2*2 这样子么?
|
2
GTim 2018-11-22 20:29:36 +08:00 1
```
#include<stdio.h> #include<string.h> #include<stdlib.h> int level(int l) { return l == 1 ? 1 : level(l-1)+1; } int main() { char ch; int a,b=1; printf("Study is a long and hard road.\n"); printf("The more you study,the further you will reach.\n"); printf("Such as if you learn 1 year, you will reached level %d.\n",level(1)); do { b=b+1; printf("such as if you learn %d years, you will reached %d level.\n", b,level(b)); printf("do you want to continue?(y/n).\n"); ch=getchar(); getchar(); } while(ch == 'y'|| ch== 'Y'); } ``` 测试格式化代码 以上是楼主代码的简化和想要的版本 |
3
FalconWang OP 感谢各位解答 问题已解决
|
4
wutiantong 2018-11-23 11:45:19 +08:00
@GTim 只有主题正文支持 markdown,回复内容不支持。。。
|