Warmachine28

prefixMax

Oct 21st, 2021 (edited)
44
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int arr[]={10,15,97,19,109};
  8. int max = INT16_MIN;
  9.  
  10. for(int i=0;i<5;i++)
  11. {
  12. if(arr[i]>max) //We can also use another array to do the same thing.
  13. {
  14. max=arr[i];
  15. arr[i]=max;
  16. }
  17. else
  18. {
  19. arr[i]=max;
  20. }
  21. cout<<arr[i]<<endl;
  22. }
  23.  
  24.  
  25.  
  26. return 0;
  27. }
RAW Paste Data Copied