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 }

 

posted @ 2016-07-27 15:24  阿豪boy  阅读(530)  评论(0编辑  收藏  举报