[TOC]
# 用随机投点法计算π值
```
#include <stdio.h>
#include <stdlib.h>
void
getT(int n) {
int i;
double x,y;
int k=0;
srand(time(0));
for(i=0;i<n;i++) {
x = rand()/(RAND_MAX+1.0);
y = rand()/(RAND_MAX+1.0);
if(x*x + y*y <= 1.0 ) k++;
}
printf("%f",4*k/(double)n);
}
int
main(void) {
getT(10000000);
return 0;
}
```