All pastes #385052 Raw Edit

Someone

public text v1 · immutable
·published 2007-03-07 15:41 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX 1000000 /*-- valor maximo que se pode assumir --*/


int main()
{

     double ltime, x=0, y=0;
     long int i=0; 
     int stime = 0;
     double num_satisfaz = 0;
     double fim;

     ltime = time(NULL);
     stime = (unsigned) ltime/2;
     mrand48(stime); //a semente usada eh o tempo.


     for (i=0; i<MAX; i++)
     {
          x = rand48();
          y = rand48();
          if ( (x*x) + (y*y) <= 1)
          {
               num_satisfaz=num_satisfaz+1;
          }

      }

     fim = ( (4 * num_satisfaz)/MAX);

     printf("%f", fim);

     return 0;
}