fork(2) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int random() {
  6. float x;
  7. srand((unsigned)time(NULL));
  8. x = rand()%100+1;
  9. x = x/100;
  10. return x;
  11. }
  12.  
  13. float prob() {
  14. float p;
  15. printf("Probabilidade: ");
  16. scanf("%f", &p);
  17. return p;
  18. }
  19.  
  20. int label(float lattice[][4], float p) {
  21. for(int i = 0; i < 4 ; i++)
  22. for(int j = 0; j < 4; j++) {
  23. lattice[i][j] = random();
  24. }
  25.  
  26. for(int i = 0; i < 4; i++)
  27. for(int j = 0; j < 4; j++) {
  28. if(lattice[i][j] <= p)
  29. lattice[i][j] = 1;
  30. else
  31. lattice[i][j] = 0;
  32. }
  33. return 0;
  34. }
  35.  
  36. int main() {
  37. float lattice[4][4];
  38. float p = prob();
  39. label(lattice, p);
  40. return 0;
  41. }
Success #stdin #stdout 0s 2056KB
stdin
2
stdout
Probabilidade: