Удалить find_max.cpp
This commit is contained in:
47
find_max.cpp
47
find_max.cpp
@@ -1,47 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
setlocale(0, "");
|
||||
int n;
|
||||
cout << "Введите размер массива n: ";
|
||||
cin >> n;
|
||||
|
||||
if (n <= 0) {
|
||||
cout << "n должно быть положительным" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int *arr = new int[n];
|
||||
|
||||
srand(static_cast<unsigned int>(time(0)));
|
||||
for (int i = 0; i < n; ++i) {
|
||||
arr[i] = rand() % 61 - 30; // значения в диапазоне [-30; 30]
|
||||
}
|
||||
|
||||
cout << "Array:\n";
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cout.width(4);
|
||||
cout << arr[i];
|
||||
if ((i + 1) % 10 == 0) cout << endl;
|
||||
}
|
||||
if (n % 10 != 0) cout << endl;
|
||||
|
||||
int maxValue = arr[0];
|
||||
int indexMax = 0;
|
||||
for (int i = 1; i < n; ++i) {
|
||||
if (arr[i] > maxValue) {
|
||||
maxValue = arr[i];
|
||||
indexMax = i;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "max: " << maxValue << " index: " << indexMax << endl;
|
||||
|
||||
delete[] arr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user