Advertisement
a53

calcfunct

a53
Nov 5th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. int pozitie_maxim(int v[],int lv)
  5. {
  6. int maxnr=v[1],pozmax=1;
  7. for(int i=2;i<=lv;++i)
  8. if(v[i]>maxnr)
  9. maxnr=v[i],pozmax=i;
  10. return pozmax;
  11. }
  12.  
  13. void pozitie_minim(int v[],int lv,int &pozmin)
  14. {
  15. int minnr=v[1];
  16. pozmin=1;
  17. for(int i=2;i<=lv;++i)
  18. if(v[i]<minnr)
  19. minnr=v[i],pozmin=i;
  20. }
  21.  
  22. void afisare(int v[],int pozInit,int pozFin)
  23. {
  24. ofstream g("calcfunct.out");
  25. for(int i=pozInit;i<=pozFin;++i)
  26. g<<v[i]<<' ';
  27. g.close();
  28. }
  29.  
  30. int main()
  31. {
  32. int n;
  33. ifstream f("calcfunct.in");
  34. f>>n;
  35. int a[n+1];
  36. for(int i=1;i<=n;++i)
  37. f>>a[i];
  38. f.close();
  39. int pmax=pozitie_maxim(a,n);
  40. int pmin;
  41. pozitie_minim(a,n,pmin);
  42. if(pmin>pmax)
  43. swap(pmin, pmax);
  44. int i=pmin,j=pmax;
  45. while(i<j)
  46. swap(a[i], a[j]),++i,--j;
  47. afisare(a,pmin,pmax);
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement