[ create a new paste ] login | about

Link: http://codepad.org/rhW7wckv    [ raw code | output | fork ]

proch - Perl, pasted on May 4:
@numeri = (3,66,2,34,12,57);
$lunghezza = 0;

# Inizializzo due variabili con il primo numero dell'array
# serviranno a tenere minimo e massimo
$min = $numeri[0];
$max = $numeri[0];

foreach $i (@numeri) {
    $lunghezza++;
    $somma = $somma + $i;
    if ($min > $i) {
       $min = $i;
    }
    if ($max < $i) {
        $max = $i;
    }

    print "Il numero corrente e': $i (per ora min: $min e max: $max)\n";

}

$lunghezza_alternativa = $#numeri + 1;
if ($lunghezza > 0) {
    $media = $somma / $lunghezza;
}

print "\nLunghezza dell'array: $lunghezza (o $lunghezza_alternativa)
Il numero minimo:     $min
Il numero massimo:    $max
La media:             $media";


Output:
1
2
3
4
5
6
7
8
9
10
11
Il numero corrente e': 3 (per ora min: 3 e max: 3)
Il numero corrente e': 66 (per ora min: 3 e max: 66)
Il numero corrente e': 2 (per ora min: 2 e max: 66)
Il numero corrente e': 34 (per ora min: 2 e max: 66)
Il numero corrente e': 12 (per ora min: 2 e max: 66)
Il numero corrente e': 57 (per ora min: 2 e max: 66)

Lunghezza dell'array: 6 (o 6)
Il numero minimo:     2
Il numero massimo:    66
La media:             29


Create a new paste based on this one


Comments: