Advertisement
patryk178

Untitled

Jan 27th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     ofstream fout("plik.txt");
  9.  
  10.     for(int i=1;i<=16;i++)
  11.     {
  12.         fout<<i<<endl;
  13.     }
  14.  
  15.     fout.close();
  16.     ifstream fin("plik.txt");
  17.  
  18.  
  19.     int tab[16];
  20.     int i=0;
  21.     while(!fin.eof())
  22.     {
  23.         fin>>tab[i];
  24.  
  25.         i++;
  26.     }
  27.  
  28.     for(int i=0;i<16;i++)
  29.     {
  30.         if(tab[i]<15)cout<<tab[i]<<",";
  31.     }
  32.  
  33.     float srednia = 0;
  34.  
  35.     int a = 0;
  36.     i=0;
  37.     for(int i=0;i<16;i++)
  38.     {
  39.  
  40.         if(tab[i]<11)
  41.         {
  42.             a++;
  43.             srednia+=tab[i];
  44.         }
  45.     }
  46.  
  47.     srednia/=a;
  48.     cout<<endl<<srednia;
  49.  
  50.     ofstream fout2("plik2.txt");
  51.     for(int i=0;i<16;i++)
  52.     {
  53.         if(tab[i]%3!=0)fout2<<tab[i]<<endl;
  54.     }
  55.  
  56.     fout2.close();
  57.     cout<<endl;
  58.     ifstream fin2("plik2.txt");
  59.     while(!fin2.eof())
  60.     {
  61.         int x;
  62.         fin2>>x;
  63.         cout<<x<<",";
  64.     }
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement