阶乘

题目截图:

 

思路:

  暴力解。

代码如下:

 1 /*
 2     阶乘 
 3 */
 4 
 5 #include <stdio.h>
 6 #include <string.h>
 7 #include <math.h>
 8 #include <stdlib.h>
 9 #include <time.h>
10 
11 int main() {
12     int n;
13     while(scanf("%d", &n) != EOF) {
14         int i, ans=1, y1=0, y2=0;    // ans 存储阶乘 
15         for(i=1; i<=n; ++i) {        // 遍历 
16             ans *= i;
17             if(i&1) {                // 若 i 为奇数 
18                 y1 += ans;
19             } else {                // 若 i 为偶数 
20                 y2 += ans;
21             }
22         }
23         // 输出 
24         printf("%d %d
", y1, y2);
25     }
26 
27     return 0;
28 }

 

原文地址:https://www.cnblogs.com/coderJiebao/p/HustTest26.html