Answer to Question #233679 in C++ for Brie

Question #233679

Write a program that accepts 10 values from the user at the keyboard and stores them in an array .Pass the array and it's size to a function that determines and displays the smallest and largest of the 10 values.


1
Expert's answer
2021-09-06T00:17:41-0400


#include <iostream>


using namespace std;


void getSmallest_and_largest(int arr[], int n){
    int min=arr[0];
    int max=arr[0];
    
    for(int i=0;i<n;i++){
        if (arr[i]<min)
            min=arr[i];
    }
    
    for(int i=0;i<n;i++){
        if (arr[i]>max)
            max=arr[i];
    }
    cout<<"\nThe smallest number in the array is: "<<min;
    cout<<"\nThe largest number in the array is: "<<max;
}
int main()
{
    int n=10;
    int arr[n];
    
    cout<<"\nEnter ten numbers:\n";
    for(int i=0;i<10;i++){
        cin>>arr[i];
    }


    getSmallest_and_largest(arr,n);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS