CPP 24
Replace min max By larsborg on 15th April 2020 05:09:44 AM
  1.  #include<bits/stdc++.h>
  2.     using namespace std;
  3.  
  4.     int main()
  5.     {
  6.  
  7.     int n,i,p,xy,y; // no need for p , i, xy, and y.
  8.     int maxi,mini;
  9.     cin>> n;
  10.     int x[n];
  11.  
  12.     for(i=0;i<n;i++){      // u can delete the braces if there's just one statement
  13.     cin>>x[i];
  14.     }
  15.  
  16.     maxi=mini=x[0];
  17.  
  18.    
  19.  
  20.     for(i=0;i<n;i++){
  21.  
  22.     if(x[i]>maxi)maxi=x[i];
  23.     if(x[i] <mini)mini=x[i];
  24.  
  25.     }
  26.  
  27.    
  28.     for(i=0;i<n;i++){
  29.     if(x[i]==maxi){
  30.         x[i]=mini; // change it to x[i] = mini;
  31.        
  32.        
  33.     }
  34.    
  35.     if(x[i]=mini){
  36.           x[i]=maxi
  37.  
  38.     }
  39.     }
  40.     for(i=0;i<n;i++){
  41.     cout<< x[i]<< " ";
  42.     }
  43.     }

PasteBin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Lars Jansen Internet Consulting
Need some advise before starting your online business strategy or project?
Get in touch!
Cleanse Your CSS!
On average, about 35% of CSS code is completely unnecessary. We meticulously find and remove this unnecessary CSS code.
Raw Paste

Login or Register to edit or fork this paste. It's free.