#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { double x, y; int nc, nq; int i; int N = 10000000; double R, R2; R = 0.7; R2=R*R; nc = 0; nq = 0; for (i=0; i<N; i++) { x =drand48(); y = drand48(); if (x*x+y*y<R2) { nc ++; } nq ++; } printf("%f (%f)\n", 4.*nc/nq/R2, M_PI); }