0$房天下问答|C语言求阶乘函数$https://m.fang.com/ask/ask_1628304.html$https://static.soufunimg.com/common_m/m_public/201511/images/asksharedefault.png
packc/pages/ask/detail/detail?askid=1628304
-
C语言求阶乘函数
#include "stdio.h"#include "math.h"main(){int n; scanf("%d",&n); printf("%d",f(n));}int f(int n){ int c,m; if(m==0) f(m)=1; c=n*f(n-1); return c;}这个程序怎么错了?
更多
共1个回答
-
-
-
wyyl08
丨Lv 0
基本思路没有问题;函数f定义有错误正确且最为规范的语句为#include "stdio.h" //没必要包含math.h,程序没用到其中的任何东西;int f(int n);void main() //须指明函数类型,空为void{int n; scanf("%d",&n); printf("%d",f(n));} int f(int n) { if(n==0) return 1; else return n*f(n-1);} “if(m==0) f(m)=1;”这语句没有意义,函数功能是通过调用参数(n)来实现的,计算结果是通过return语句来实现的;你这里定义的m是一个未被赋值的没有意义的变量,被定义后其值无意义且恒定,不能用来做判断,应直接用参数n来做判断并将结果用return返回而不是令它等于多少
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。

关注成功