jncrusher

o co kamam

Oct 15th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5. #include <iostream>
  6. #include <fstream>
  7. using namespace std;
  8. #define A 8
  9.  
  10. int do_dziesietnego(int tab[]){
  11.     /*for(int i=0;i<A;i++){
  12.         cout<<tab[i];
  13.     }
  14.     cout<<endl;*/
  15.     int wynik=0;
  16.  
  17.     for(int i=A-1; i>=0;i--){
  18.         int ile=A-(i+1);
  19.         wynik=wynik+(pow(2.0,ile)*tab[i]); 
  20.     }
  21. return wynik;  
  22. }
  23.  
  24. int main(){
  25.     srand (time(NULL));
  26.     int wsp_x[A];
  27.     int wsp_y[A];
  28.     fstream plik;
  29.     plik.open("rozrzut.txt", ios::app);
  30.  
  31.     for(int i=0; i<A;i++){
  32.         wsp_x[i]=rand()%2;
  33.         wsp_y[i]=rand()%2;
  34.     }
  35.    
  36.     cout<<"Te wartości to: ";
  37.     for(int i=0;i<A;i++){
  38.     cout<<wsp_x[i];
  39.     }
  40.     cout<<"\t";
  41.     for(int i=0;i<A;i++){
  42.     cout<<wsp_y[i];
  43.     }
  44.     cout<<endl;
  45.     cout<<"Dziesietnie to: "<<do_dziesietnego(wsp_x)<<"\t"<<do_dziesietnego(wsp_y)<<endl;
  46.    
  47.     for(int g=0; g<300;g++){
  48.         int losowa=rand()%A;
  49.         if (wsp_x[losowa]==1)
  50.             wsp_x[losowa]=0;
  51.         else
  52.             wsp_x[losowa]=1;
  53.         losowa=rand()%A;
  54.         if (wsp_y[losowa]==1)
  55.             wsp_y[losowa]=0;
  56.         else
  57.             wsp_y[losowa]=1;
  58.         plik <<do_dziesietnego(wsp_x)<< '\t' ;
  59.         plik <<do_dziesietnego(wsp_y)<< endl;
  60.         }
  61.     plik.close();
  62.     system("pause");
  63.     return 0;
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment