Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <windows.h>
  4. using namespace std;
  5. void wyswietl(int tab[],int n)
  6. {
  7. for(int i=0;i<n;i++)
  8. {
  9. cout<<tab[i]<<" ";
  10. }
  11. }
  12. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  13.  
  14. int main(int argc, char** argv) {
  15. cout<<"podaj n"<<endl;
  16. int n,max,min,maxp=0,minp=0;
  17. cin>>n;
  18. int tab[n];
  19. for(int i=0;i<n;i++)
  20. {
  21. tab[i]=rand()%100+1;
  22. }
  23. wyswietl(tab,n);
  24. min=tab[0];
  25. max=tab[1];
  26.  
  27. for(int x=0;x<n;x++)
  28. {
  29. if(tab[x]<min){
  30. min=tab[x];
  31. minp=x;
  32. }
  33. if(tab[x]>max)
  34. {max=tab[x];
  35. maxp=x;
  36. }
  37.  
  38. }
  39.  
  40. cout<<endl<<"MIN / MAX"<<endl;
  41. cout<<"MIN"<<" : "<<min<<" na pozycji "<<minp<<endl;
  42. cout<<"MAX"<<" : "<<max<<" na pozycji "<<maxp;
  43.  
  44.  
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement