Advertisement
Guest User

prosjek

a guest
Jun 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. //lucasov
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <fstream>
  5. #include <ctime>
  6. #include <cmath>
  7. #include <cstring>
  8. using namespace std;
  9.  
  10. int main(){
  11.     srand(time(0));
  12.     unsigned int start=rand()%(5-1+1)+1;
  13.     unsigned int max=0;
  14.     ofstream prvi("a_1.txt",ios::out);
  15.     int br=0;
  16.     while(max<pow(2,20)){
  17.         max+=rand()%(5-1+1)+1;
  18.         prvi<<max<<"\n";
  19.         br++;
  20.     }
  21. //----------------------------------------------
  22.     prvi.close();
  23.     int b1,b2,zbr=0;
  24.     ifstream PRVI("a_1.txt");
  25.     int br1=0;
  26.     for(int i=0;i<br;i++){
  27.         if(i==0){
  28.             PRVI>>b1;
  29.         }
  30.         PRVI>>b2;
  31.         zbr+=b2-b1;
  32.         b1=b2;
  33.         br1++; 
  34.     }
  35.     float avg=zbr/br1;    cout<<avg<<"\n";
  36. //----------------------------------------------
  37. //----------------------------------------------
  38.     ofstream drugi("a_2.txt",ios::out);
  39.     PRVI.clear();
  40.     PRVI.seekg(0);
  41.     int br2=0;
  42.     for(int i=0;i<br;i++){
  43.         if(i==0){
  44.             PRVI>>b1;
  45.             //drugi<<tmp;
  46.         }
  47.         PRVI>>b2;
  48.        
  49.         if((b2-b1)>avg){
  50.             drugi<<b1<<"\n";
  51.             //drugi<<b2<<"\n";
  52.         }
  53.         b1=b2;
  54.         br2++;
  55.     }
  56.     PRVI.close();
  57.     drugi.close();
  58. //----------------------------------------------   
  59.     ifstream DRUGI("a_2.txt");
  60.     zbr=0;
  61.     int br3=0;
  62.     for(int i=0;i<br2;i++){
  63.         if(i==0){
  64.             DRUGI>>b1;
  65.         }
  66.         DRUGI>>b2;
  67.         zbr+=b2-b1;
  68.         b1=b2;
  69.         br3++;
  70.     }
  71.     float avg2=zbr/br3;      cout<<avg2<<"\n";
  72.     DRUGI.clear();
  73.     DRUGI.seekg(0);
  74. //-----------------------------------------------
  75.     ofstream treci("a_3.txt",ios::out);
  76.     br2=0;
  77.     for(int i=0;i<br3;i++){
  78.         if(i==0){
  79.             DRUGI>>b1;
  80.         }
  81.         DRUGI>>b2;
  82.         if((b2-b1)>avg2){
  83.             treci<<b2<<"\n";
  84.         }
  85.         b1=b2;
  86.         br2++;
  87.     }
  88.     DRUGI.close();
  89.     treci.close();
  90. //------------------------------------------------
  91.     ifstream TRECI("a_3.txt");
  92.     zbr=0;
  93.     br=0;
  94.     for(int i=0;i<br2;i++){
  95.         if(i==0){
  96.             TRECI>>b1;
  97.         }
  98.         TRECI>>b2;
  99.         zbr+=b2-b1;
  100.         b1=b2;
  101.         br++;  
  102.         }
  103.     TRECI.close();
  104.     float avg3=zbr/br;
  105.     cout<<avg3;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement