第1个回答 2018-01-29
#include <stdio.h>
#include <stdlib.h>
//^_^ 13的问题,题主怕已经是大佬了 献丑了
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int i, j;
long sum=0;
for(i=1,j=1;i<=3;){ // 3改成你想要的数字 别太大 太大会超出c语言的int类型的数值范围
if( j%2 == 0 ){
sum -=jc(i); //偶数次运算为 -
} else {
sum +=jc(i); //奇数次计算为 +
}
i= i+2;
j++;
}
printf(" the sum is %d\n",sum);
return 0;
}
//计算num的阶乘
int jc(num){
if(num==1){ //1 的阶乘为1 直接返回
return 1;
}
return num*jc(num-1); // 3的阶乘为 3*2! 2的阶乘为 2*1! n的阶乘为 n* (n-1)!
}
第3个回答 2018-01-29
#include<stdio.h>
int fun(int n);
int main(void)
{
int n = 0;
int count = 0;
for (int i=1; i<=101; i+=2){
n++;
if(n%2==0){
count -= fun(i);
}else{
count += fun(i);
}
}
printf("%d",count);
}
int fun(int n)
{
if(n==0||n==1)
return 1;
else
return n*fun(n-1);
}
//我在java编辑器里写完改的C,你粘贴到编辑器运行一下试试,应该没有什么问题