标签:阶乘计算 计算 math led void printf out put clu
10
3628800
c++代码如下:
#include <stdio.h>
#include <stdlib.h>
int num[5000];
int jcjs(int num[],int n){
num[0]=1;
int len=1;
int i;
for(i=1;i<=n;++i){
len=0;
int p = 0;
int jw=0;
while(num[p]!=-1){
num[p]*=i;
num[p]+=jw;
jw=0; //进位加完置零
if(num[p]>=10){
jw=num[p]/10;
num[p]%=10;
}
p++;
len++;
}
if(jw!=0){
while(jw){ //进位值不一定是1位 要循环处理
num[p++]=jw%10;
jw/=10;
len++;
}
}
}
return len-1;
}
int main(int argc, char *argv[]) {
int n;
while(scanf("%d",&n)!=EOF){
memset(num,-1,sizeof(num));
int len = jcjs(num,n);
for(len;len >=0;--len){
printf("%d",num[len]);
}
printf("\n");
}
return 0;
}
java代码如下:
import java.math.BigInteger;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
BigInteger s=BigInteger.ONE;
for(int i=1;i<=n;i++){
s=s.multiply(new BigInteger(i+""));
}
System.out.println(s);
}
}
python代码如下:
n=int(input())
i=1
s=1
while(i<=n):
s*=i
i+=1
print(s)
标签:阶乘计算 计算 math led void printf out put clu
原文地址:https://www.cnblogs.com/cstdio1/p/12114384.html