fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int FIND_ELE(int *ARR,int &N)
  5. {
  6. int K=1,SMALL=ARR[0],LARGE=ARR[0];
  7. while(K<N)
  8. {
  9. if(ARR[K]<SMALL)
  10. SMALL=ARR[K];
  11. if(ARR[K]>LARGE)
  12. LARGE=ARR[K];
  13. K++;
  14. }
  15. cout<<"Smallest Element Is: "<<SMALL<<endl;
  16. cout<<"Largest Element Is: "<<LARGE<<endl;
  17. return 0;
  18. }
  19.  
  20.  
  21. int main()
  22. {
  23. int N;
  24. cin>>N;
  25. int ARR[N];
  26. for(int i=0;i<N;i++)
  27. cin>>ARR[i];
  28.  
  29. FIND_ELE(ARR,N);
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 5280KB
stdin
7
7 5 8 4 12 10 5
stdout
Smallest Element Is: 4
Largest Element Is: 12