标签:inpu ret main col printf print return long for
#include<stdio.h> int main() { int m; long ret; printf("Input m:"); scanf("%d",&m); ret = Fact(m); printf("%d!=%ld\n",m,ret); return 0; } long Fact(int n) { int i; long result = 1; for(i=2;i<=n;i++) { result *=i; } return result; }
改良:
#include<stdio.h> int main() { int m; long ret; printf("Input m:"); scanf("%d",&m); ret = Fact(m); printf("%d!=%ld\n",m,ret); return 0; } long Fact(int n) { if(n<0) return -1; else if(n==0||n==1) return 1; else return n*Fact(n-1);//n*(n-1)*···*fact(1) }
标签:inpu ret main col printf print return long for
原文地址:https://www.cnblogs.com/jiangzenghui/p/12445764.html