include stdafx include iostream include iomanip define EPSILON 00001 u

 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
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#define EPSILON 0.00001
using namespace std;
float my_func(float x);
void print(float(*func)(float), float x[], int s);
void main()
{
cout.precision(4);
float x[] = { -1, -0.5, 0, 0.5, 1 };
print(my_func, x, 5);
cin.get();
}
float my_func(float x)
{
float result = 2 * x, itog = result;
for (int i = 1; abs(result *= 2 * x / (i + 1)) > EPSILON; i++)
itog += result;
return itog;
}
void print(float(*func)(float), float x[], int s)
{
cout.width(16);
cout << left << "X" << right << "Y" << endl;
for (int i = 0; i < s; i++){
cout.width(16);
cout << left << x[i] << right << fixed << func(x[i]) << endl;
}
}