0
How to find and print the smallest element of the array?
1 Antwort
0
#include <iostream>
using namespace std;
int min(int x[],int l)
{
int minim=x[0];
for (int i=0; i<l; i++)
{
if (x[i] < minim)
minim = x[i];
}
return minim;
}
int max(int x[],int l)
{
int maxim=x[0];
for (int i=0; i<l; i++)
{
if (x[i] > maxim)
maxim = x[i];
}
return maxim;
}
int main() {
int n;
cout <<"How long is the array?\n";
cin>>n;
cout <<"Enter the array values:\n";
int sir[100];
for (int i=0; i<n; i++)
cin>>sir[i];
cout<<"Smallest value in array is: "<<min(sir,n)<<endl;
cout<<"Largest value in array is: "<<max(sir,n)<<endl;
return 0;
}