Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- using namespace std;
- int minimal(double arr[], int len) {
- int min_index = 0;
- for (int i = 1; i < len; i++) {
- if (arr[i] < arr[min_index]) {
- min_index = i;
- }
- }
- return min_index;
- }
- int main()
- {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- int N{};
- string words_array[10]{ "перший", "другий", "третій", "четвертий", "п'ятий", "шостий", "сьомий", "восьмий", "дев'ятий", "десятий" };
- while (true) {
- cout << "Введіть бажану кількість елементів у масиві (від 2 до 10): ";
- cin >> N;
- if (cin.fail() || N < 2 || N > 10) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Число було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- double* array = new double[N];
- for (int i = 0; i < N; i++) {
- while (true) {
- cout << "Введіть " << words_array[i] << " елемент масиву: ";
- cin >> array[i];
- if (cin.fail()) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Число було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- }
- cout << "Індекс мінімального елемента в масиві: " << minimal(array, N);
- delete[] array;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement