#include #include #include #include // per il seed int main() { float x, y, A; int N; time_t t; unsigned RandomSeed; printf("Dai il nr di punti\n"); scanf("%d", &N); printf("N = %d\n", N); // RandomSeed = 12345; RandomSeed = (unsigned) time(&t); srand( RandomSeed ); int nIN = 0; for (int i=0; i < (N); i++) { x = (float) rand() / (float) RAND_MAX; y = (float) rand() / (float) RAND_MAX; if( (x*x + y*y) <= 1. ) nIN += 1; } printf("nIN = %d \n", nIN); A = (float) nIN / N; printf("Area = %f (esatta %f)\n", A, acos(-1)/4.); puts("\nStima di pi greco"); printf("Dall'area: %f\n", 4 * A); return 0; }