Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. void P(int a[100], unsigned int k, int &max)
  7. {
  8.  
  9. max=a[1];
  10. int i;
  11.  
  12. for (i=1; i<=k; i++)
  13. {
  14. if(max<a[i])
  15. max=a[i];
  16.  
  17. }
  18.  
  19. }
  20.  
  21. int main()
  22. {
  23.  
  24. unsigned int k;
  25. int a[100], max=a[1];
  26.  
  27. cin>>k;
  28.  
  29. for (int i=1; i<=k; i++)
  30. cin>>a[i];
  31.  
  32. for (int i=1; i<=k; i++) {
  33. P(a, i, max);
  34. a[i]=max;
  35. cout<<a[i]<<" ";
  36. }
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement