输入一个正整数n:
n为奇数,输出1!+3!+5!+...+n!
n为偶数,输出1!+3!+5!+...+(n+1)!
具体代码:
#include<stdio.h>int main(){int sum=0;int n;printf("请输入n:");scanf("%d",&n);if(n%2==0);n++;for(int i=1;i<=n;i++){int p=1;for(int j=i;j<=i;j++){p*=j;}sum+=p;}printf("sum=%d",sum);return 0;
}
测试输出:
觉得有帮助的话点个赞吧!