Answer the question
In order to leave comments, you need to log in
Why does printf output #INF0 when adding 1500 numbers less than 1?
YP - C.
Wrote this loop:
int i,n;
double t_i,rnd,sum;
sum=0.0;
n=1500;
for (i=0;i<n;i++){
rnd = (rand()%1001)/1000.0; // от 0 до 1
t_i = (-1.0)*log(rnd)/5.333; // не превышает единицы
sum=t_i+sum;
printf("rnd: %.5f, log(rnd): %.5f, t_i: %.5f, sum: %.5f\n\n",rnd,log(rnd),t_i,sum);
}
rnd: 0.56000, log(rnd): -0.57982, t_i: 0.10872, sum: 1.#INF0
rnd: 0.42200, log(rnd): -0.86275, t_i: 0.16178, sum: 1.#INF0
rnd: 0.17900, log( rnd): -1.72037, t_i: 0.32259, sum: 1.#INF0
rnd: 0.28600, log(rnd): -1.25176, t_i: 0.23472, sum: 1.#INF0
rnd: 0.02500, log(rnd): -3.68888, t_i: 0.69171, sum: 1.#INF0
rnd: 0.13000, log(rnd): -2.04022, t_i: 0.38257, sum: 1.#INF0
rnd: 0.74900, log(rnd): -0.28902, t_i: 0.05419, sum: 1.#INF0
rnd: 0.30100, log(rnd): -1.20065, t_i: 0.22514, sum: 1.#INF0
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question