-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculo_de_serie.c
82 lines (70 loc) · 1.46 KB
/
calculo_de_serie.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//https://thehuxley.com/problem/1114?quizId=5563
#include <stdio.h>
#include <string.h>
#include <math.h>
double result[120000];
double par(int n)
{
double numerator = pow(2,n-1);
double denominator = 3*(n/2);
//printf("%.0lf/%.0lf +",numerator,denominator);
double ans = numerator/denominator;
return ans;
}
double impar(int n)
{
double denominator = pow(2,n-1);
double numerator = n;
//printf("%.0lf/%.0lf +",numerator,denominator);
double ans = numerator/denominator;
return ans;
}
double series(int n_max, double ans, int i)
{
if (i == n_max+1)
{
return ans;
}
else
{
if(i%2 == 0)
{
double now = par(i);
double new_ans = now+ans;
//printf("new_ans=%.2lf\n",new_ans);
return series(n_max,new_ans,i+1);
}
else if(i%2 != 0)
{
double now = impar(i);
double new_ans = now+ans;
//printf("new_ans=%.2lf\n",new_ans);
return series(n_max,new_ans,i+1);
}
}
}
int main()
{
int n;
scanf("%d",&n);
if (n == 0)
{
double result = 0.00;
printf("S: %.2lf\n",result);
}
else if (n == 1)
{
double result = 1.00;
printf("S: %.2lf\n",result);
}
else if (n < 0)
{
return 0;
}
else
{
double tre = series(n,1,2);
printf("S: %.2lf\n",tre);
return 0;
}
}