#include "stdafx.h"//del
#include <iostream>
#include <cmath>
#include <complex>
using namespace std;
complex<double> func(int x)
{
complex<double > result (0,0);
complex<double > tmp(x, 0);
result = cos(tmp) + sqrt(tmp);
return result;
}
int main()
{
//Вариант 7 нахождение функции y(x), где x Є[a, b] (-4,3)с шагом h.
int a = -3, b = 2, h = 1;
complex<double> result(0, 0);
cout << "var1: for " <<endl;
for (int x = a; x <= b; x++)
{
result = func(x);
if (result.imag() == 0)
cout << "x= " << x << " f(x)= " << result.real() << endl;
else
if (result.imag() == 1)
cout << "x= " << x << " f(x)= " << result.real() << " + i" << endl;
else
cout << "x= " << x << " f(x)= " << result.real() << " + " << result.imag() << "i" << endl;
}
cout << endl << "var2: while " << endl;
int X = a;
while (X <= b)
{
result = func(X);
if (result.imag() == 0)
cout << "x= " << X << " f(x)= " << result.real() << endl;
else
if (result.imag() == 1)
cout << "x= " << X << " f(x)= " << result.real() << " + i" << endl;
else
cout << "x= " << X << " f(x)= " << result.real() << " + " << result.imag() << "i" << endl;
X++;
}
cout << endl << "var3: do while " << endl;
int eks = a;
do {
result = func(eks);
if (result.imag() == 0)
cout << "x= " << eks << " f(x)= " << result.real() << endl;
else
if (result.imag() == 1)
cout << "x= " << eks << " f(x)= " << result.real() << " + i" << endl;
else
cout << "x= " << eks << " f(x)= " << result.real() << " + " << result.imag() << "i" << endl;
eks++;
} while (eks <= b);
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.