c语言使用概率计算积分值
计算x2在0到1间的面积
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main(int argc, char *argv[]) 5 { 6 int i,k,n; 7 n=100000; //循环总次数 8 k=0; 9 double x,y; 10 for(i=0;i<n;i++){ 11 x=(rand()%100)/100.0; //产生0到1之间的随机数 12 y=(rand()%100)/100.0; 13 if(y<=x*x) k++; 14 } 15 16 printf("the area is %lf\n",(double)k/(double)n); 17 return 0; 18 }