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.
#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);
}
Comments
Leave a comment