08.10.2012, 18:26. Просмотров 1300. Ответов 21
Четвёртый член ряда равен 0.001411 (можете проверить запустив программу)
Вопрос: почему не срабатывает строчка (последняя) if(E<b) printf("Sum ryada do tochnosty %f ravna: %f\n", E, w); Когда 0.0001<0.001411?
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
| #include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int function();
int main()
{
int factor, count, n, q, sum;
float x;
double y, z, w;
double b;
float E; //это наша точность
E = 0.0001;
w = 0; // для подсчёта суммы ряда
x = 2
for(n=1;n<=5;n++) {
y = pow(x, 2*n+1);
z = pow(-1.0, n);
printf("y: %.0f\nz: %.0f\n", y, z);
q = 2*n+1;
factor=1;
for(count=1;count<=q;count++) factor= factor*count;
printf("Faktorial chisla %d raven %d\n", q, factor);
b = z/factor*y;
printf("%f\n\n", b);
w = b+w;
if (n==5) cout << w << '\n';
}
if(E<b) printf("Sum ryada do tochnosty %f ravna: %f\n", E, w);
system("pause");
return 0;
} |
|