Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- #include <iostream>
- #include <fstream>
- using namespace std;
- #define A 8
- int do_dziesietnego(int tab[]){
- /*for(int i=0;i<A;i++){
- cout<<tab[i];
- }
- cout<<endl;*/
- int wynik=0;
- for(int i=A-1; i>=0;i--){
- int ile=A-(i+1);
- wynik=wynik+(pow(2.0,ile)*tab[i]);
- }
- return wynik;
- }
- int main(){
- srand (time(NULL));
- int wsp_x[A];
- int wsp_y[A];
- fstream plik;
- plik.open("rozrzut.txt", ios::app);
- for(int i=0; i<A;i++){
- wsp_x[i]=rand()%2;
- wsp_y[i]=rand()%2;
- }
- cout<<"Te wartości to: ";
- for(int i=0;i<A;i++){
- cout<<wsp_x[i];
- }
- cout<<"\t";
- for(int i=0;i<A;i++){
- cout<<wsp_y[i];
- }
- cout<<endl;
- cout<<"Dziesietnie to: "<<do_dziesietnego(wsp_x)<<"\t"<<do_dziesietnego(wsp_y)<<endl;
- for(int g=0; g<300;g++){
- int losowa=rand()%A;
- if (wsp_x[losowa]==1)
- wsp_x[losowa]=0;
- else
- wsp_x[losowa]=1;
- losowa=rand()%A;
- if (wsp_y[losowa]==1)
- wsp_y[losowa]=0;
- else
- wsp_y[losowa]=1;
- plik <<do_dziesietnego(wsp_x)<< '\t' ;
- plik <<do_dziesietnego(wsp_y)<< endl;
- }
- plik.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment