0

How to find and print the smallest element of the array?

23rd Oct 2016, 1:54 PM
sundar
sundar - avatar
1 ответ
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; }
28th Oct 2016, 5:49 PM
Mihai Benegui
Mihai Benegui - avatar