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
|
#include <iostream>
using namespace std;
int smallestIndex(int array[], int arraySize);
int lastLargestIndex(int array[]); int arraySize);
int main()
{
const int MAX_ARRAY_SIZE = 15;
int test[MAX_ARRAY_SIZE] {16, 22, 4, 17, 21, 84, 43, 62, 53, 24, 35, 13,
29, 16, 29};
int smallestPosition = smallestIndex(test, MAX_ARRAY_SIZE);
cout << "The smallest index position is: " << smallestPosition << ".";
cout << "The value of the smallest index is: " << test[smallestPosition] << ".";
int largestPosition = lastLargestIndex(test, MAX_ARRAY_SIZE);
cout << "The largest index position is: " << largestPosition << ".";
cout << "The value of the largest index is: " << test[largestPosition];
return 0;
}
/*int main()
{
const int MAX_ARRAY_SIZE = 15;
int test[MAX_ARRAY_SIZE] {16, 22, 4, 17, 21, 84, 43, 62, 53, 24, 35, 13,
29, 16, 29};
int largestPosition = lastLargestIndex(test, MAX_ARRAY_SIZE);
cout << "The largest index position is: " << largestPosition << ".";
cout << "The value of the largest index is: " << test[largestPosition];
return 0;
}
(this is what it looked like before I tried to combine them)*/
int smallestIndex(int array[], int arraySize)
{
int smallest = 0;
for (int i = 0; i < arraySize - 1; i++)
{
if (array[i] < array[smallest]) smallest = i;
}
return smallest;
}
int lastLargestIndex(int array [], int arraySize)
{
int largest = 0;
for (int i = 0, i < arraySize; i++)
{
if (numberArray[i] >= largest) largest = i;
}
return largest;
}
|