Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- #define FRANDOM ((double) random()/RAND_MAX)
- #define N 1e6 // não poderia inicializar vetor
- int main(void)
- {
- double x, y, nacertos;
- for (double n=1; n<N; n*=2) {
- nacertos = 0.0;
- for (int i = 0; i < N; ++i)
- {
- x = FRANDOM;
- y = FRANDOM;
- double f = x*x + y*y;
- if (f<1)
- nacertos++;
- }
- printf("%lf\t%lf\n",n,(nacertos/N)*4); // se não 1e6 -> (double) N
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement