题解 | #阶乘#
阶乘
https://www.nowcoder.com/practice/e58c8a55162d49c48115bdfa5da7da56
#include <stdio.h> //阶乘函数 long factorial(int n){ long ret=1; for(int i=1;i<=n;i++){ ret*=i; } return ret; } int main() { int a; long y1=0,y2=0; while (scanf("%d", &a) != EOF) { // 注意 while 处理多个 case for(int i=1;i<=a;i++){ if(i%2==1){ y1+=factorial(i); }else{ y2+=factorial(i); } } } printf("%ld %ld",y1,y2); return 0; }