Facebook
From xd, 4 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 162
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12.     ofstream plik("losowe1.txt");
  13.     srand( time( NULL ) );
  14.     int los[500]={};
  15.     for(int i = 0; i < 100; i++){
  16.  
  17.         los[i]=(rand() % 450) + 50;
  18.  
  19.         plik << los[i] << endl;
  20.         }
  21.     int L[500]={};
  22.  
  23.     ifstream in("losowe1.txt");
  24.  
  25.     for(int i = 0; i< 100; i++)
  26.     {
  27.        in >> L[i];
  28.  
  29.     }
  30.  
  31.     for(int i = 0; i < 99; i++)
  32.     {
  33.         for(int j=0; j < 99; j++)
  34.             if(L[j]>L[j+1])
  35.                 swap(L[j],L[j+1]);
  36.     }
  37.  
  38.     ofstream of("posorowane1.txt");
  39.  
  40.     for(int i = 0; i < 100; i++){
  41.         cout << L[i] << endl;
  42.         of << L[i] << endl;
  43.  
  44.     }
  45.     return 0;
  46. }