• - Media dei Voti

/*******************Ricerca Media*******************************/
/*   Programma per ricercare la media dei voti di un esame     */
/*   eseguito da n studenti                                    */
/*                                                             */
/***************************************************************/

#include 

int main(void)
{
    int d = 0, n, voto, somma = 0, i;   

    /* Inserisci il numero di studenti */
    scanf("%d",&n);

    for (i = 0; i < n; i++) {
        d++;
        printf("%d. ", d);
    /* Inserisci voto studente n° d */        
        scanf("%d",&voto);
    /* Somma il voto dello studente d agli altri voti */        
        somma = somma + voto;        
    /* Se il voto č < 0 o > 30, non considerare il voto, valido */
        if (voto < 0 || voto > 30) {
           printf("Hai inserito un voto non valido. Reinserisci il voto corretto\n");
           somma = somma - voto;
           d--;
           i--;
        }
    }
    /* Stampa media voti di tutti gli studenti */    
    printf("%.3f", somma /(float)n);
    
    return 0;
}

-- AndreaBandino - 24 Nov 2002

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2003-10-04 - AndreaSterbini






 
Questo sito usa cookies, usandolo ne accettate la presenza. (CookiePolicy)
Torna al Dipartimento di Informatica
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback