-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
83 lines (70 loc) · 2.03 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int size, limits;
srand(time(nullptr));
b:cout << "Enter array size: ";
cin >> size;
cout << "Enter the biggest value for the number in the array: ";
cin >> limits;
if (size < 1)
{
cout << "Error. Array size can't be less than one.";
cin.get();
goto b;
}
if (limits < size)
{
cout << "Error. The biggest number can't be less than the array size." << endl;
goto b;
}
int *arr = new int [size];
for (int i = 0; i < size; i++)
{
a:arr[i] = rand() % limits;
for (int j = 0; j < i; j++)
{
if (arr[i] == arr[j]) goto a;
}
}
cout << "Non-repeating pseudo-random numbers: ";
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
int max = arr[0];
int min = arr[0];
for (int r = 0; r < size; r++)
{
if (max < arr[r])max = arr[r];
if (min > arr[r])min = arr[r];
}
cout << "\nMaximum value: " << max << endl;
cout << "Minimum value: " << min << endl;
s:cout << "Do you want to perform manipulations with the array?\nAddition (1)\n"
"Subtraction (2)\nMultiplication (3)\nDivision (4)" << endl;
cout << "Enter the command number: ";
int CommandNumber;
cin >> CommandNumber;
switch (CommandNumber)
{
case 1:
cout << "Sum addition: " << (max + min) << endl;
break;
case 2:
cout << "Sum subtraction: " << (max - min) << endl;
break;
case 3:
cout << "Sum multiplication: " << (max * min) << endl;
break;
case 4:
cout << "Sum division: " << (max / min) << endl;
break;
default:
cout << "Error. You entered the wrong command number. Enter the command number again: " << endl;
goto s;
}
delete [] arr;
}