Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. double metodoRan(double max, double min)
  6. {
  7.     double range = (max - min);
  8.     double div = RAND_MAX / range;
  9.     return min + (rand() / div);
  10. }
  11.  
  12. int producedureDirectPi(int N)
  13. {
  14.     int nHits = 0;
  15.     double x = 0;
  16.     double y = 0;
  17.     for(i = 0; i < N; i++)
  18.     {
  19.         x = metodoRan (1, -1);
  20.         y = metodoRan (1, -1);
  21.         if ( (x*x) + (y*y) ) < 1)
  22.             {
  23.                 nHits = nHits++;
  24.             }
  25.     }
  26.     return nHits;
  27. }
  28.  
  29. int main( int argc, const char* argv[] )
  30. {
  31.     srand (time ( NULL)); //Cria a base de calculo randomico baseado no tempo da máquina
  32.     int N;
  33.     printf("Entre com o parametro N: ");
  34.     scanf("%d", &N);
  35.     int result = producedureDirectPi(N);
  36.     printf("The result is: %d\n", result);
  37.     return 0;  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement