Advertisement
Guest User

wysol piznąl laską o podłogę

a guest
Nov 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. n = prompt("Podaj ile ma byc ocen");
  2. n = parseInt(n);
  3. var oceny = [];
  4. for(i = 0; i < n ; i++){
  5. oceny.push(Math.floor(Math.random() * 6) + 1);
  6. }
  7. document.write(oceny);
  8. var suma = 0;
  9. for(i = 0; i < n ; i++){
  10. suma = suma + oceny[i];
  11. }
  12. var srednia = suma/n;
  13. document.write('<br>'+srednia);
  14. var powyzej = 0;
  15. var ponizej = 0;
  16. for(i = 0; i < n ; i++){
  17. if(oceny[i] > srednia){
  18. powyzej++;
  19. }
  20. else if(oceny[i] < srednia){
  21. ponizej++;
  22. }
  23. else{
  24. }
  25. }
  26. document.write('<br>'+"Liczb powyzej sredniej jest: " + powyzej + ", a liczb ponizej jest: " + ponizej);
  27.  
  28.  
  29. var indeks = 0;
  30. for(i = 0; i < n; i++){
  31. var minimal = oceny[i];
  32. for(j = i; j < n;j++){
  33. if(oceny[j] < minimal){
  34. minimal = oceny[j];
  35. indeks = j;
  36. }
  37. }
  38. if (minimal < oceny[i]){
  39. var bufor = oceny[i];
  40. oceny[i] = minimal;
  41. oceny[indeks] = bufor;
  42. }
  43. }
  44. document.write('<br>'+oceny);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement