Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- double metodoRan(double max, double min)
- {
- double range = (max - min);
- double div = RAND_MAX / range;
- return min + (rand() / div);
- }
- int producedureDirectPi(int N)
- {
- int nHits = 0;
- double x = 0;
- double y = 0;
- for(i = 0; i < N; i++)
- {
- x = metodoRan (1, -1);
- y = metodoRan (1, -1);
- if ( (x*x) + (y*y) ) < 1)
- {
- nHits = nHits++;
- }
- }
- return nHits;
- }
- int main( int argc, const char* argv[] )
- {
- srand (time ( NULL)); //Cria a base de calculo randomico baseado no tempo da máquina
- int N;
- printf("Entre com o parametro N: ");
- scanf("%d", &N);
- int result = producedureDirectPi(N);
- printf("The result is: %d\n", result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement