Problem
Please write out the program output.
Solution
Actually, it requires to compute (Pi * R2 / 4) / R2 * LOOP. So it is reasonable to give any number around 1000 * Pi / 4
include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define LOOP 1000
void main()
{
int rgnC = 0;
//srand((unsigned)time(NULL));
for(int i = 0; i < LOOP; i++){
int x = rand();
int y = rand();
if( x*x + y * y < RAND_MAX * RAND_MAX){
rgnC ++;
}
}
printf("%d\n", rgnC);
}
Output
778