Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <iomanip>

#include <iostream>
#include <math.h>

using namespace std;


float x; // �������� ����. ����
float k = 0; // �������� ������. ����
float sum = 0; // ���� ���
float error; // ������� ����������
float member; // ������� ���

long double Power( long double x, long double y) {


if (y == 0) {
return 1;
} else {
if (y == 1) {
return x;
}
else {
return x * Power(x, y - 1);
}
}
}

// �������� �������� ����������


void OutputSum()
{
cout << setw(5) << x << setw(10) << k << setw(20) << member << setw(15) << sum
<< endl;
}

// ��������� �������� ���� �� ����


void MemberAndSum()
{
double Numerator; //��������� �������� ����
double Denominator; // �������� �������� ����
for (x = 1; x <= 5; x++)
{
k = 0;
do
{
Numerator=Power(-1,k)*sqrt(x+1);
if (k > 32)
{
cout << "overflow - break cycle with k" << endl;
break;
}
else if(k==0)
{
cout << setw(5) << x << setw(10) << k << setw(20) << "Impossible" <<
setw(15) << "Impossible" << endl;
k++;
}
else if(x==1)
{
cout << setw(5) << x << setw(10) << k << setw(20) << "Impossible" <<
setw(15) << "Impossible" << endl;
x++;
}
else
{
Denominator=Power((1-Power(x,k)),2);
member = (float)Numerator / Denominator;
sum = sum + member;
OutputSum();
k++;
}
}

while (fabs(member) < error); // ���� �� ������ ������� �������


}
}

int main()
{
int a;
cout << "Ilia Kozachyshyn" << endl;
cout << "IPZ-12" << endl;
cout << "To calculate the sum of row" << endl;

cout << "5 endlessneess" << endl;


cout << " sum (sum (((-1)^k)* sqrt(x+1))/((1-x^k)^2))" << endl;
cout << "x = 1 k=0" << endl;
cout << "input error:";
cin >> error;
cout << "result:" << endl;
cout << "=================================================="<< endl;
cout << " x k member sum" << endl;
cout << "=================================================="<< endl;
MemberAndSum();
cout << "=================================================="<< endl;
cout << "sum=" << sum << endl;
cout << endl;
cout<< "Press 1 to repeat or 2 to exit"<<endl;
cin>>a;
cout << endl;
switch(a){
case 1:
main();
break;
case 2:
return 0;
break;
system("pause");
}
}

You might also like