© Éditions Eyrolles
245
Correction des exercices
while (i<4)
{ printf ("donnez un entier ") ;
scanf ("%d", &n) ;
som += n ;
i++ ;
/* ni cette "incrémentation" */
}
printf ("Somme : %d\n", som) ;
}
b)
#include
main()
{ int i, n, som ;
som = 0 ;
i = 0 ;
/* ne pas oublier cette "initialisation" */
do
{ printf ("donnez un entier ") ;
scanf ("%d", &n) ;
som += n ;
i++ ;
/* ni cette "incrémentation" */
}
while (i<4) ;
/* attention, ici, toujours <4 */
printf ("Somme : %d\n", som) ;
}
Exercice 5.2 :
#include
main()
{ float note,
/* note courante */
som,
/* somme des notes */
moy ;
/* moyenne des notes */
int num ;
/* numéro note courante */
som=0 ; num=0 ;
while ( printf("note %d : ",num+1),
scanf ("%f", ¬e), note>=0 )
{ num++ ;
som += note ;
}
Delannoy Livre.book Page 245 Mercredi, 6. mai 2009 4:27 16
245
Correction des exercices
while (i<4)
{ printf ("donnez un entier ") ;
scanf ("%d", &n) ;
som += n ;
i++ ;
/* ni cette "incrémentation" */
}
printf ("Somme : %d\n", som) ;
}
b)
#include
main()
{ int i, n, som ;
som = 0 ;
i = 0 ;
/* ne pas oublier cette "initialisation" */
do
{ printf ("donnez un entier ") ;
scanf ("%d", &n) ;
som += n ;
i++ ;
/* ni cette "incrémentation" */
}
while (i<4) ;
/* attention, ici, toujours <4 */
printf ("Somme : %d\n", som) ;
}
Exercice 5.2 :
#include
main()
{ float note,
/* note courante */
som,
/* somme des notes */
moy ;
/* moyenne des notes */
int num ;
/* numéro note courante */
som=0 ; num=0 ;
while ( printf("note %d : ",num+1),
scanf ("%f", ¬e), note>=0 )
{ num++ ;
som += note ;
}
Delannoy Livre.book Page 245 Mercredi, 6. mai 2009 4:27 16
