Answer:
#include <iostream>
using namespace std;
int arrayMinimum(int myArray[], int myArraySize) {
int small = myArray[0];
for (int i = 0; i < myArraySize; i++) {
if(myArray[i]<small){
small = myArray[i];
}
}
return small;
}
int main(){
int myArray[20];
for(int i =0;i<20;i++){
cin>>myArray[i];
}
cout<<"The smallest is: "<<arrayMinimum (myArray,20);
return 0;
}
Explanation:
This solution is provided in c++
#include <iostream>
using namespace std;
This line defines the arrayMinimum function
int arrayMinimum(int myArray[], int myArraySize) {
This initializes the smallest of the array element to the first
int small = myArray[0];
This iterates through the array
for (int i = 0; i < myArraySize; i++) {
This if condition checks for the smallest
if(myArray[i]<small){
The smallest is assigned to the small variable
small = myArray[i];
}
}
This returns the smallest
return small;
}
The main method begins here
int main(){
This declares an array of 20 elements
int myArray[20];
The following iteration allows user input into the array
<em> for(int i =0;i<20;i++){
</em>
<em> cin>>myArray[i]; </em>
<em> }
</em>
This calls the method and returns the minimum
cout<<"The smallest is: "<<arrayMinimum (myArray,20);
return 0;
}