Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #define n 10 // hst.length = n
- #define N 10000
- int main(void)
- {
- double hst[n]={0};
- double dx = (double) 1/n;
- double x;
- int i,j;
- // for (j=0; j<n; j++)
- // hst[j]=0;
- for (i=0; i<N; i++) {
- x = sqrt((double) rand()/RAND_MAX);
- // printf("%lf\n",x);
- for (j=0; j<n; j++) {
- if (x>=j*dx && x<(j+1)*dx) {
- hst[j]++;
- }
- }
- }
- // printf("\n");
- for (j=0; j<n; j++) {
- printf("%lf \n",hst[j]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement