Advertisement
Guest User

Untitled

a guest
Sep 29th, 2014
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. long a[51];
  6. int n,m,k=1;
  7.  
  8. void citire()
  9. {
  10.     ifstream fin("sort.in");
  11.     fin>>n;
  12.  
  13.     for (int i=1; i<=n; i++)
  14.         fin>>a[i];
  15.  
  16. }
  17.  
  18. void prelucrare()
  19. {
  20.     ofstream fout("sort.out");
  21.     int i,j;
  22.     long aux,min;
  23.         for(i=1;i<=n-1;i++)
  24. {
  25.     min=a[i];
  26.     k=i;
  27.     for(j=i+1;j<=n;j++)
  28.         if(a[j]<min)
  29.         {
  30.             min=a[j];
  31.             k=j;
  32.         }
  33.     aux=a[i];
  34.     a[i]=a[k];
  35.     a[k]=aux;
  36. }
  37.     for(i=1;i<=n;i++)
  38.     fout<<a[i]<<" ";
  39.  
  40. }
  41.  
  42.  
  43. int main()
  44. {
  45.     citire();
  46.     prelucrare();
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement