@-=ЮрА=-
Заблокирован
|
21.12.2012, 13:07
|
|
shilovec5377, вот корректное решение
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
| #include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
double PI = 2*asin(1.0);
double Y(double x)
{
return (3*pow(x, 2.0) - 6*PI*x + 2*pow(PI, 2.0)) / 12;
}
double S(double x, double e)
{
double Sum = 0;
double k = 1;
double an = cos(k*x) / pow(k, 2.0);
for(k = k + 1; e < fabs(an); k = k + 1)
{
Sum += an;
an = cos(k*x) / pow(k, 2.0);
}
return Sum;
}
int main()
{
double a;
double b;
double h;
double e;
double y;
double s;
cout<<"Enter a : ";cin>>a;
cout<<"Enter b : ";cin>>b;
cout<<"Enter h : ";cin>>h;
cout<<"Enter e : ";cin>>e;
cout<<"---------------------------"<<endl;
cout<<"| x | Y(x) | S(x) |"<<endl;
cout<<"---------------------------"<<endl;
for(double x = a; x <= b; x = x + h)
{
y = Y(x);
s = S(x, e);
cout<<"|"<<setw(7)<<(x < 0 ? setprecision(4) : setprecision(5))<<x
<<"|"<<setw(8)<<(y < 0 ? setprecision(4) : setprecision(5))<<y
<<"|"<<setw(8)<<(s < 0 ? setprecision(4) : setprecision(5))<<s
<<"|"<<endl;
}
return 0;
} |
|
1
|