#include <iostream>
#include <windows.h>
#include <iomanip>
using namespace std;
void task40()
{
cout << "Task 40" << endl;
cout << "Input n " << endl;
int y = 1, n, i = 1, s;
cin >> n;
s = (2 * n) - 1;
for (i; i <= s; i += 2)
{
y *= i;
}
cout << y << endl;
/*while (i <= s)
{
y = y * i;
i += 2;
}
cout << y << endl;*/
}
void task75()
{
cout << "Task 75 " << endl;
double s = 50;
for (int i = 50; 0 < i; i--)
{
s = (i - 1) + pow(s, 0.5);
}
cout << s << endl;
}
void task5()
{
cout << "Task 5 " << endl;
int a2, a3, i, xmi = 1, xm = 10, step = 1;
cout << "-----------------------------" << endl;
cout << "| a | a^2 | a^3 |" << endl;
cout << "-----------------------------" << endl;
for (i = xmi; i <= xm; i += step)
{
a2 = pow(i, 2);
a3 = pow(i, 3);
cout << "|" << setw(7) << i << "|" << setw(9) << a2 << "|" << setw(9) << a3 << "|"<< endl;
}
cout << "-----------------------------" << endl;
}
void task250()
{
cout << "Task 250 " << endl;
int y = 0, b = -5, a = 3;
for (double x = 1; x <= 5; x += 0.5)
{
y = a * x * x + b;
cout <<"x=" << setw(3) << x << "\ty=" << y <<endl;
}
cout << endl;
}
void task110()
{
bool nPrime = true;
int result = 0;
cout << " Task 110 " << endl;
for (int i = 0; i <= 40; i++)
{
result = pow(i,2) + i + 41;
cout << "x = " << i << "\tResult = " << result;
for (int x = 2; x < result; x++)
{
if (result % x == 0)
{
nPrime = false;
break;
}
}
cout << (nPrime ? "\tsimple" : "\tnot simple");
nPrime = true;
cout << endl;
}
cout << endl;
}
void task215()
{
double a1 = 2, an = a1, eps = 1E-3;
int n = 0;
do
{
a1 = an;
an = (2 + pow(a1,2)) / (2 * a1);
cout << setw(16) << setprecision(15) << a1 << setw(20) << setprecision(15) << an << endl;
n++;
} while (fabs(an - a1) > eps);
cout << "Lowest number: " << (n - 1) << endl;
cout << endl;
}
void task180()
{
cout << "Task 180" << endl;
bool power1 = true,power2 = true;
cout << "Input number" << endl;
cin >> number;
while (number > 3 && power1)
{
if (number % 3 == 0)
{
number /= 3;
}
else power1 = false;
if (number % 5 == 0)
{
number /= 5;
}
else power2 = false;
}
cout << (power1 && number % 3 == 0 ? "Number is power of 3" : "Number isn't power of 3") << endl;
cout << (power2 && number % 5 == 0 ? "Number is power of 5" : "Number isn't power of 5") << endl;
cout << endl;
}
void task145()
{
cout << "Task 145 " << endl;
int number, n1, n2, n3, n = 0;
do
{
cout << "Input number (from 6 to 100)" << endl;
cin >> number;
} while (number < 6 || number > 100);
const int size = 24;
int arrSimple[size] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89};
for (int i = 0; i < size ; i++)
{
for (int u = i; u < size; u++)
{
for (int y = u; y < size; y++)
{
if (arrSimple[i] + arrSimple[u] + arrSimple[y] == number)
{
cout << arrSimple[i] << " + " << arrSimple[u] << " + " << arrSimple[y] << " = " << number << endl;
}
}
}
}
}
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
setlocale(LC_ALL, "Russian");
int n = 1;
while (n != 0)
{
cout << "Choose task " << endl;
cin >> n;
switch (n)
{
case 40:
task40();
break;
case 75:
task75();
break;
case 5:
task5();
break;
case 250:
task250();
break;
case 110:
task110();
break;
case 215:
task215();
break;
case 180:
task180();
break;
case 145:
task145();
}
if (n == 0) return 0;
}
}