目录
方法一:递归法求阶乘
方法二:循环法求阶乘
main及结果
方法一:递归法求阶乘
long Factorial_way1(int m){if(m==1)return 1;else{return m*Factorial_way1(m-1);}}
方法二:循环法求阶乘
long Factorial_way2(int m){long sum=1;int i;for(i=1;i<=m;i++)sum*=i;return sum;}
main及结果
void main()
{printf("%d\n",Factorial_way1(5));printf("%d\n",Factorial_way2(5));
}
本文链接:https://my.lmcjl.com/post/5778.html
展开阅读全文
4 评论