/* ------------------------------------ */ /*exo1.c*/ /* ------------------------------------ */ #include int main (void) { int i; i = 1; while (i<=50) { printf("%d ",i); i=i+1; } ; printf("\n"); return 0; } /* ------------------------------------ */ /*exo2.c*/ /* ------------------------------------ */ #include int main (void) { int i; i = 50; while (i>=1) { printf("%d ",i); i=i-1; } ; printf("\n"); return 0; } /* ------------------------------------ */ /*exo3.c*/ /* ------------------------------------ */ #include #include int main (void) { int ent1,ent2; int imin,imax,i; scanf("%d %d",&ent1,&ent2); imin = min(ent1,ent2); imax = max(ent1,ent2); i = imin; while (i<=imax) { if (i%2 == 0) {printf("%d ",i);}; i=i+1; } ; printf("\n"); return 0; } /* ------------------------------------ */ /*exo4.c*/ /* ------------------------------------ */ #include #include int calcule_suivant(int u) { if (u%2 == 0) {return (u/2);} else {return (3*u+1);} ; } int main (void) { int A; int res,compteur; scanf("%d",&A); res = A; compteur = 0; while (res!=1) { res = calcule_suivant(res); printf(" %d\n",res); compteur = compteur + 1; } ; printf("resultat : U_%d=1 \n",compteur); return 0; } /* ------------------------------------ */ /*exo5.c*/ /* ------------------------------------ */ #include #include int main (void) { int note_courante; int min_tmp; int max_tmp; int nb_notes; int somme_tmp; double moyenne; /*initialisation obligatoire*/ scanf("%d",¬e_courante); nb_notes = 0; somme_tmp = 0; while (note_courante != -1) { nb_notes = nb_notes+1; /*le premier tour*/ if (nb_notes == 1) { min_tmp = note_courante; max_tmp = note_courante; somme_tmp = note_courante; } else { somme_tmp = somme_tmp + note_courante; min_tmp = min(min_tmp,note_courante); max_tmp = max(max_tmp,note_courante); }; scanf("%d",¬e_courante); }; if (nb_notes != 0) { moyenne = ((double) somme_tmp) / ((double) nb_notes); printf("%d notes de %d/20 a %d/20, moyenne %f/20\n",nb_notes,min_tmp,max_tmp,moyenne); }; return 0; }