fork(1) 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++) lattice[i][j] = random();
  23. for (int i = 0; i < 4; i++)
  24. for (int j = 0; j < 4; j++) {
  25. if (lattice[i][j] <= p) lattice[i][j] = 1;
  26. else lattice[i][j] = 0;
  27. }
  28. return 0;
  29. }
  30.  
  31. int main() {
  32. float lattice[4][4];
  33. float p = prob();
  34. label(lattice, p);
  35. }
  36.  
  37. //https://pt.stackoverflow.com/q/76582/101
Success #stdin #stdout 0s 4204KB
stdin
2
stdout
Probabilidade: