计算1!+2!+3!+...+n!

/*
计算1!+2!+3!+4!+5!+.....+20!
计算1!+2!+3!+...+n!; 
*/
#include <stdio.h>
float fun(float n){
    float i,s=0,a=1;
    for(i=1;i<=n;i++){
        a=a*i;
        s=s+a;
    }
    return s;
}
int main(){
    float s=0,n;
    scanf("%f",&n);
    s=fun(n);
    printf("%f\n",s);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/byczyz/p/13385506.html
今日推荐