I´m writing a program where I have an array with numbers and I need to find the smallest an the biggest number in the array. The teacher made the example here below and I need to finish the functions below with a for- loop but I dont know how, can someone help me?
int find_smallest_number(int number[], int n);
int find_biggest_number(int number[], int n);
int main()
{
int smallest_number = find_smallest_number(number, n);
int biggest_number = find_biggest_number(number, n);
for (int a = smallest_number; a <= biggest_number; a++) {
cout << a << ": " << number_of_people(department, number);
}
return 0;
}
int find_smallest_number(int number[], int n){
//for loop
// what to do?
}
int find_biggest_number(int number[], int n){
//for loop
// what to do?
}
int find_smallestNumber( int number[] , int n )
{
int smallestNumber;
// Assume that the first element is the smallest number
Assign the value of the first element, number[0] to smallestNumber
// Using for loop, iterate through the entire array and find any number that is smaller than
// current smallestNumber
for( From int index = 1 to and not including n )
if number[index] is smaller than smallestNumber
Assign number[index] to smallestNumber
// After the for-loop exits, smallestNumber variable will have the smallest element
// from the array
return smallestNumber;
}
Use the same logic for finding the biggest number.