2011

求多项式的和

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     int m, n, i, f = -1;
 6     double j,sum = 0;
 7     while (scanf_s("%d", &m))
 8     {
 9         for (i = 1;i <= m;i++)
10         {
11             scanf_s("%d",&n);
12             f *= -1;
13             j = 1.0 * f / i;
14             sum += j;
15             printf("%.2lf
",sum);
16         }
17     }
18     return 0;
19 }

参考答案

 1 #include<stdio.h>
 2 
 3 int n;
 4 
 5 double rev(int c)
 6 {
 7     return c <= n ?( ((c & 1) ? 1.0 : -1.0) / c + rev(c + 1) ): 0 ;
 8 }
 9 
10 int main()
11 {
12     int t;
13 
14     scanf("%d", &t);
15     while (t-- && scanf("%d", &n))
16         printf("%.2lf
", rev(1));
17 
18     return 0;
19 }
========================if i have some wrong, please give me a message, thx.========================
原文地址:https://www.cnblogs.com/ailx10/p/5327822.html