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