#include "stdafx.h"//del
#include <iostream>
#include <cmath>
#include <complex>
using namespace std;
void printC(complex<double > result)
{
if (result.imag() == 0)
cout << "answer= " << result.real() << endl;
else
if (result.imag() == 1)
cout << "answer= " << result.real() << " + i" << endl;
else
cout << "answer= " << result.real() << " + " << result.imag() << "i" << endl;
}
complex<double> funcLeft(int A, int B, int plus)
{
complex<double > result(0, 0);
complex<double > a(A, 0);
complex<double > b(B, 0);
if (plus == 1)
result = sqrt(a + sqrt(b));
else
result = sqrt(a - sqrt(b));
return result;
}
complex<double> funcRight(int A, int B, int plus)
{
complex<double > result(0, 0);
complex<double > a(A, 0);
complex<double > b(B, 0);
complex<double > two(2, 0);
if (plus == 1)
result = sqrt((a + sqrt(a*a - b) / two)) + sqrt((a - sqrt(a*a - b) / two));
else
result = sqrt((a + sqrt(a*a - b) / two)) - sqrt((a - sqrt(a*a - b) / two));
return result;
}
int main()
{
complex<double> result(0, 0);
int aStart;
cout << "aStart= ";
cin >> aStart;
int aEnd;
cout <<endl << "aEnd= ";
cin >> aEnd;
int bStart;
cout << endl << "bStart= ";
cin >> bStart;
int bEnd;
cout << endl << "bEnd= ";
cin >> bEnd;
cout << endl << "======================================= " << endl;
for (int A = aStart; A <= aEnd; A++)
{
for (int B = bStart; B <= bEnd; B++)
{
cout << endl << "A = " <<A << endl;
cout << endl << "B = " <<B <<endl;
cout << endl << "!!!!!!!!!!!!Plus: !!!!!!!!!!!!!!" << endl;
cout << endl << "Left: " << endl;
result = funcLeft(A, B, 1);
printC(result);
cout << endl << "Right: " << endl;
result = funcRight(A, B, 1);
printC(result);
cout << endl << "!!!!!!!!!!!!Minus: !!!!!!!!!!!!!!" << endl;
cout << endl << "Left: " << endl;
result = funcLeft(A, B, 0);
printC(result);
cout << endl << "Right: " << endl;
result = funcRight(A, B, 0);
printC(result);
}
cout << endl << "======================================= " << endl;
}
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.