#include <iostream>
#include <cmath>
using namespace std;
void task3()
{
cout << "task(a)" << endl;
const int size = 15;
int i = 0;
double arr[size];
for (i = 0; i < size; i++)
{
arr[i] = rand() % 10 * 0.1;
cout << arr[i] << " ";
}
cout << endl << endl;
cout << "task(b)" << endl;
for (i = 0; i < size; i++)
{
arr[i] = rand() % 10 * 0.1 + 22;
cout << arr[i] << " ";
}
cout << endl << endl;
cout << "task(c)" << endl;
for (i = 0; i < size; i++)
{
arr[i] = rand() % 100 * 0.1;
cout << arr[i] << " ";
}
cout << endl << endl;
cout << "task(d)" << endl;
for (i = 0; i < size; i++)
{
arr[i] = rand() % 1000 * 0.1 - 50;
cout << arr[i] << " ";
}
cout << endl << endl;
cout << "task(e)" << endl;
for (i = 0; i < size; i++)
{
arr[i] = rand() % 11;
cout << arr[i] << " ";
}
cout << endl << endl;
}
void task38()
{
const int size = 10;
int arr[size];
int t;
cout << "Our array : ";
for (int i = 0; i < size; i++)
{
arr[i] = i + 1;
cout << arr[i] << " ";
}
cout << endl << endl;
for (int i = 0; i < size; i++)
{
if (i % 2 == 0 && i < 9)
{
swap(arr[i], arr[i + 1]);
}
}
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
cout << endl << endl;
}
void task73()
{
int a = 0, k;
double n;
double arr[15];
double m[15];
for (int i = 0; i < 15; i++)
{
a += 5;
arr[i] = a * 0.1;
cout << arr[i] << " ";
}
cout << endl;
cout << "Enter n :";
cin >> n;
double c, p, l=0, e = 0;
p = abs(n - arr[0]);
for (int i = 0; i < 15; i++)
{
c = abs(n - arr[i]);
if (c < p)
l = i, e = arr[i];
p = c;
}
cout << endl;
cout << "Number is " << l + 1 << " Znachenie is " << e;
cout << endl << endl;
}
void task108()
{
int arr[7];
for (int i = 0; i < 7; i++)
{
arr[i] = rand() % 10;
if (i == 6)
{
arr[i] = pow(arr[0], 2);
}
cout << arr[i] << " ";
}
cout << endl << endl;
}
void task143()
{
int kx, ky;
int x[30];
int y[30];
double maxX = x[0];
double maxY = y[0];
double distancex, distancey, distance;
for (int i = 0; i < 30; i++)
{
x[i] = rand() % 20 - 10;
y[i] = rand() % 20 - 10;
}
for (int i = 0; i < 30; i++)
{
for (int n = 0; n < 30; n++) {
distancex = (pow(x[i] - x[n], 2));
}
if (distancex > maxX)
{
maxX = x[i];
kx = i++;
}
for (int n = 0; n < 30; n++) {
distancey = (pow(y[i] - y[n], 2));
}
if (distancey > maxY)
{
maxY = y[i];
ky = i++;
}
}
distance = sqrt(distancex + distancey);
cout << "Number point x:" << kx << " " << "Number point y:" << ky << endl;
cout << "Distance : " << distance << endl;
}
void task178()
{
int long n = 0, a = 0, b = 1, factN = 1;
cout << "Enter n : ";
cin >> n;
int* arr = new int[n];
for (int i = 0; i < n; i++)
{
arr[i] = rand() % 10 + 1;
if (i == n - 1) arr[i] = n;
cout << arr[i] << " ";
}
cout << endl << endl;
for (int i = 0; i < n; i++)
{
b *= arr[i];
}
for (int k = 2; k <= n; k++)
{
factN *= k;
}
cout << b << " " << factN << endl;
if (b == factN)
{
cout << "is a permutation of natural numbers";
}
else cout << "is not a permutation of natural numbers";
}
int main()
{
system("cls");
int number;
tryagain:
cout << "Numbers of the tasks: 3, 38, 73, 108, 143,178" << endl;
cout << "Enter number of the task(enter 0 to exit)..." << endl;
cin >> number;
switch (number)
{
case(3):
{
task3();
goto tryagain;
}
case(38):
{
task38();
goto tryagain;
}
case(73):
{
task73();
goto tryagain;
}
case(108):
{
task108();
goto tryagain;
}
case(143):
{
task143();
goto tryagain;
}
case(178):
{
task178();
goto tryagain;
}
case(0):
{
return 0;
break;
}
default:
{
cout << "Invalid number" << endl;
goto tryagain;
}
}
}