Answer to Question #235195 in C++ for makwapa

Question #235195

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


1
Expert's answer
2021-09-10T18:53:59-0400
#include<iostream>
using namespace std;




void maxMin(int arr[], int n){
	


 int min = arr[0];
   
    for(int i = 0; i < n; i++){
        if(arr[i] < min){
            min = arr[i];
        }
    }
    cout<<"The smallest is:  "<<min<<endl;
    
     int max = arr[0];
   
    for(int i = 0; i < n; i++){
        if(arr[i] > max){
            max= arr[i];
        }
    }
    cout<<"The  largest is:  "<<max<<endl;
    
	
}
int main(){
	int arr[10];
	cout<<"Enter the elements of the array\n";
	for(int i=0; i<10; i++){
		cout<<"Element:  "<<(i+1)<<endl;
		cin>>arr[i];
	}
	maxMin(arr, 10);
}

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