fork download
  1. #include<time.h>
  2. #include<stdlib.h>
  3. #include<stdio.h>
  4.  
  5. double float_rand(int nLow, int nHigh){
  6. double dec_part = (rand()%100)*0.01;
  7. float int_part = (rand()%(nHigh-nLow))+nLow;;
  8. return int_part+dec_part;
  9. }
  10.  
  11. double getNum(double target, double mistake){
  12. mistake/=100;
  13. return float_rand(target*(1-mistake), target*(1+mistake));
  14. }
  15.  
  16. double count_mis(double target, double rand){
  17. return (double)((rand-target)/target)*100;
  18. }
  19. int main(int argc, char *argv[]){
  20. printf("A X C\n");
  21. int i,count=50;
  22. (unsigned)time(NULL);
  23. double target=250;
  24. double mistake=0.4;
  25. double a=target,b;
  26. double sum=0;
  27. for(i=0;i<count;i++){
  28. b=getNum(a, mistake);
  29. sum+=(b);
  30. printf("%.2f %.2f %.2f\n", a, b, count_mis(a,b));
  31. a=b;
  32. }
  33. target*=count;
  34. printf("----------\nA X C\n%.2f %.2f %.2f", sum, target, count_mis(target, sum));
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
A X C
250.00 249.83 -0.07
249.83 249.77 -0.02
249.77 249.93 0.06
249.93 248.86 -0.43
248.86 248.49 -0.15
248.49 248.62 0.05
248.62 248.90 0.11
248.90 247.63 -0.51
247.63 246.40 -0.50
246.40 245.72 -0.28
245.72 244.11 -0.66
244.11 244.67 0.23
244.67 243.82 -0.35
243.82 243.62 -0.08
243.62 243.67 0.02
243.67 242.29 -0.57
242.29 241.22 -0.44
241.22 241.69 0.19
241.69 240.93 -0.31
240.93 239.11 -0.76
239.11 239.29 0.08
239.29 239.21 -0.03
239.21 239.84 0.26
239.84 238.98 -0.36
238.98 238.15 -0.35
238.15 237.13 -0.43
237.13 236.91 -0.09
236.91 236.56 -0.15
236.56 235.62 -0.40
235.62 235.96 0.14
235.96 235.05 -0.39
235.05 234.84 -0.09
234.84 234.36 -0.20
234.36 234.46 0.04
234.46 234.13 -0.14
234.13 234.24 0.05
234.24 234.82 0.25
234.82 234.14 -0.29
234.14 233.34 -0.34
233.34 232.43 -0.39
232.43 231.87 -0.24
231.87 230.76 -0.48
230.76 229.88 -0.38
229.88 229.03 -0.37
229.03 228.54 -0.21
228.54 227.32 -0.53
227.32 226.76 -0.25
226.76 225.39 -0.60
225.39 224.26 -0.50
224.26 224.94 0.30
----------
A X C
11907.49 12500.00 -4.74