#include"stdio.h"
int fun1(int x){
if (x<=1) return 1;
return x*fun1(x-1);
}
int fun2(int n){
int i,x=0;
for(i=1;i<=n;i++)
if (i%2==1)
x+=fun1(i);
else
x-=fun1(i);
return x;
}
int main(){
int n=5;
printf("请输入项数n\n");
scanf("%d",&n);
printf("结果是:%d\n",fun2(n));
}
#include
int fun1(int x){
if (x<=1) return 1;
return x*fun1(x-1);
}
int fun2(int n){
int i,x=0;
for(i=1;i<=n;i++)
if (i%2==1)
x+=fun1(i);
else
x-=fun1(i);
return x;
}
int main(){
int n=5;
printf("请输入项数n\n");
scanf("%d",&n);
printf("结果是:%d\n",fun2(n));
}
输入一个正整数n,输出1!-2!+3!-4!+5!.......+n!
#include