Другие языки программирования и технологии

Помогите пожалуйста решить задачку на С++ очень нужно (((

1.   При некоторых заданных x, N и E, определяемых вводом, вычислить:

a) сумму N
слагаемых заданного вида;

b) сумму тех слагаемых, которые по абсолютной величине
больше Е.
#pragma hdrstop
#pragma argsused

#include <tchar.h>
#include <stdio.h>
#include <iostream>
#include <windows.h>

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int x=1,n,e;
float s,s1;
cin >> x >> n >> e;
for (int i = 1; i < n; i++) {
s=s+(x^(i+2))/(i+2);
if (((x^(i+2))/(i+2)) > e) {
s1=s1+(x^(i+2))/(i+2);
}
}
cout << "\n"<< " s = " <<s << " s1 = " << s1;
system("PAUSE");
return 0;
}

}
Арсен Берик
Арсен Берик
1 461
Лучший ответ
#include <iostream>
using namespace std;
int main() {
    cout << " e: "; double e; cin >> e;
    cout << " x: "; double x; cin >> x;
    double sum = 0, member = x;
    bool sign = true;
    if (abs(x) > e && abs(x) < 1) {
        for (int n = 1; abs(member) > e; n += 2) {
            member = pow(x, n) / n;
            if (sign) {
                sign = false;
                sum += member;
            } else {
                sign = true;
                sum -= member;
            }
        }
        cout << " arctg(" << x << ")" << sum << endl;
    } else cout << " Error!\n";
    fflush(stdin);
    cin.get();
}
Канат Шайкенов
Канат Шайкенов
64 648
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x,n,e,d,t,s; int j;
cout<<"x="; cin>>x;
cout<<"e="; cin>>e;
j=log10(1/e)+3; cout.precision(j);
for(j=1,t=s=x;fabs(t)>e;s+=t*=-x*x/(j+2)*j,j+=2);
cout << "arctg(" << x << ")=" << atan(x) << "\tsumm=" << s << "\t|arctg(" << x << ")-" << s << "|=" << fabs(atan(x)-s) << endl;
return 0;
}