Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = prompt("Podaj ile ma byc ocen");
- n = parseInt(n);
- var oceny = [];
- for(i = 0; i < n ; i++){
- oceny.push(Math.floor(Math.random() * 6) + 1);
- }
- document.write(oceny);
- var suma = 0;
- for(i = 0; i < n ; i++){
- suma = suma + oceny[i];
- }
- var srednia = suma/n;
- document.write('<br>'+srednia);
- var powyzej = 0;
- var ponizej = 0;
- for(i = 0; i < n ; i++){
- if(oceny[i] > srednia){
- powyzej++;
- }
- else if(oceny[i] < srednia){
- ponizej++;
- }
- else{
- }
- }
- document.write('<br>'+"Liczb powyzej sredniej jest: " + powyzej + ", a liczb ponizej jest: " + ponizej);
- var indeks = 0;
- for(i = 0; i < n; i++){
- var minimal = oceny[i];
- for(j = i; j < n;j++){
- if(oceny[j] < minimal){
- minimal = oceny[j];
- indeks = j;
- }
- }
- if (minimal < oceny[i]){
- var bufor = oceny[i];
- oceny[i] = minimal;
- oceny[indeks] = bufor;
- }
- }
- document.write('<br>'+oceny);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement