fork(1) download
  1. /*
  2. Autor: Noe Lara García
  3. Curso: Estructura de datos
  4. Programa: DISTRIBUCION NORMAL
  5. Fecha: 24/02/2020
  6. */
  7. #include <iostream>
  8. #include <cmath>
  9.  
  10. using namespace std;
  11. float normal(float desvesta, float media, int K){
  12. float sum=0.0;
  13. for (int i=0;i<K;i++){
  14. sum+= (float)rand()/RAND_MAX;//No hay nada más entre r y sum, los colocamos en la misma linea para ahorrar codigo
  15. }
  16. float x=(sum-((float)K/2))*sqrt(12.0/K);
  17. return desvesta*x+media;
  18.  
  19. }
  20. int main() {
  21. int K=100;
  22. int n=100;
  23. float desvesta=1.0;
  24. float media=0.0;
  25. for (int i=0;i<n;i++){
  26. printf("%4.f\n",normal(desvesta,media,K));
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
   2
   0
   1
  -0
  -1
   3
  -0
  -1
  -0
  -0
  -0
  -1
   0
  -1
  -1
   0
   1
   0
   0
  -1
  -0
  -1
   1
  -0
   1
   1
  -0
  -1
  -2
   1
  -1
   2
  -1
  -2
   1
   1
   0
  -2
   2
  -0
  -1
   0
  -1
   1
  -1
   1
   1
  -1
  -2
  -0
   0
   2
   0
   1
  -1
   1
  -1
   1
   0
  -0
  -2
  -1
  -1
  -1
  -1
  -1
  -1
  -0
   1
   0
   0
  -0
   2
  -1
  -1
  -0
  -0
   1
   0
   1
  -1
   1
  -0
   1
  -1
  -1
  -1
   0
  -1
  -1
   0
  -0
   1
   0
  -1
  -2
  -1
   0
   0
  -1