forked from taniadovzhenko/CppPracticum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.2.1.18.c
More file actions
70 lines (54 loc) · 926 Bytes
/
task1.2.1.18.c
File metadata and controls
70 lines (54 loc) · 926 Bytes
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
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
//b)
double func_b(double x, double eps){
double a,y;
a = 1.0;
y = a;
int k=0;
while(fabs(a)>eps){
k++;
a = a * (-x) * k*k / (k+1)/(k+1); // 1, -x/1^2, x^2/3^2, .....
y += a;
}
return y;
}
// g
double func_g(double x, double eps){
double a,y;
a = x;
y = a;
int k=0;
while(fabs(a)>eps){
k++;
a = a * (-x*x) / k / (2*k)/(2*k+1); // x, -x**3/2!/3!, x**5/3!/5! , .....
y += a;
}
return y;
}
int main(){
double x,eps;
double a,y;
int k=0;
do{
printf("x(x!=0)=");
scanf("%lf",&x);
} while(fabs(x)<0.00001);
do{
printf("eps(eps>0)=");
scanf("%lf",&eps);
} while(eps<0.00001);
// b)
/*
a = 1.0;
y = a;
while(fabs(a)>eps){
k++;
a = a * (-x) * k*k / (k+1)/(k+1); // 1, -x/1^2, x^2/3^2, .....
y += a;
}
*/
y =func_g(x,eps);
printf("y=%lf",y);
}