forked from taniadovzhenko/CppPracticum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.2.9.c
More file actions
76 lines (48 loc) · 969 Bytes
/
task1.2.9.c
File metadata and controls
76 lines (48 loc) · 969 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
71
72
73
74
75
76
#include <stdio.h>
#include <math.h>
double func139a(double x, int n){
double y = 1;
double power = 1;
for(int i=1;i<=n;++i){
y += i * power; // i*pow(x,i-1);
power *= x; // x ** i
}
return y;
}
double func139c(double x, int n){
double y = 1;
double power = x; // 1, x, x^2/2!
for(int i=1;i<=n;++i){
y += power; // pow(x,i-1)/ (i)!;
power *= x /(i+1); // x^i/(i)!
}
return y;
}
double func139b(double x, int n){
double y = 1;
double power = 1;
for(int i=1;i<=n;++i){
power *=x;
}
for(int i=1;i<=n;++i){
y += i * power; // i*pow(x,i-1);
power *= (1-x)/x;
}
return y;
}
int main(){
double x,y;
unsigned n;
printf("n=");
scanf("%u",&n);
do{
printf("Input x, |x|<1, x=");
scanf("%lf",&x);
}while(fabs(x)>=1);
y = func139a(x,n);
printf("y=%lf\n",y);
y = func139b(x,n);
printf("y=%lf\n",y);
y = func139c(x,n);
printf("y=%lf\n %lf",y, exp(x));
}