Created
February 12, 2026 19:04
-
-
Save rocket-fuel86/5f5ee5a6f1b188f4cd7fe1d0e76a2930 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include "functions.h" | |
| int main() | |
| { | |
| const unsigned int LEN = 3; | |
| double array[LEN] = {}; | |
| fillArray(array, LEN); | |
| showArray(array, LEN); | |
| std::cout << maxIndex(array, LEN) << std::endl; | |
| std::cout << minIndex(array, LEN) << std::endl; | |
| } | |
| ################################### functions.h ################################################## | |
| #pragma once | |
| #include <iostream> | |
| void fillArray(double array[], const unsigned int arrayLength) | |
| { | |
| for (unsigned int i = 0; i < arrayLength; i++) | |
| { | |
| std::cin >> array[i]; | |
| } | |
| } | |
| void showArray(double array[], const unsigned int arrayLength) | |
| { | |
| for (unsigned int i = 0; i < arrayLength; i++) | |
| { | |
| std::cout << array[i] << ' '; | |
| } | |
| std::cout << std::endl; | |
| } | |
| int maxIndex(double array[], const unsigned int arrayLength) | |
| { | |
| double max = array[0]; | |
| int maxIndex = 0; | |
| for (unsigned int i = 1; i < arrayLength; i++) | |
| { | |
| if (array[i] > max) | |
| { | |
| max = array[i]; | |
| maxIndex = i; | |
| } | |
| } | |
| return maxIndex; | |
| } | |
| int minIndex(double array[], const unsigned int arrayLength) | |
| { | |
| double min = array[0]; | |
| int minIndex = 0; | |
| for (unsigned int i = 1; i < arrayLength; i++) | |
| { | |
| if (array[i] < min) | |
| { | |
| min = array[i]; | |
| minIndex = i; | |
| } | |
| } | |
| return minIndex; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment