fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. char nom[50];
  5. float note1, note2, note3;
  6. float moyenne, pourcentage;
  7.  
  8. // 1. Demander le nom
  9. printf("Entrez le nom de l'etudiant : ");
  10. scanf("%s", nom);
  11.  
  12. // 2. Demander les 3 notes
  13. printf("Entrez la note 1 sur 20 : ");
  14. scanf("%f", &note1);
  15. printf("Entrez la note 2 sur 20 : ");
  16. scanf("%f", &note2);
  17. printf("Entrez la note 3 sur 20 : ");
  18. scanf("%f", &note3);
  19.  
  20. // 3. Calcul moyenne
  21. moyenne = (note1 + note2 + note3) / 3.0; // 3.0 force le float
  22.  
  23. // 4. Calcul pourcentage : conversion de type pour être précis
  24. pourcentage = ((moyenne / 20.0) * 100.0);
  25.  
  26. // 5. Affichage avec 2 chiffres après la virgule
  27. printf("\n===== RESULTATS =====\n");
  28. printf("Nom de l'etudiant : %s\n", nom);
  29. printf("Notes : %.2f, %.2f, %.2f\n", note1, note2, note3);
  30. printf("Moyenne generale : %.2f / 20\n", moyenne);
  31. printf("Pourcentage de reussite : %.2f %%\n", pourcentage);
  32. printf("=====================\n");
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Entrez le nom de l'etudiant : Entrez la note 1 sur 20 : Entrez la note 2 sur 20 : Entrez la note 3 sur 20 : 
===== RESULTATS =====
Nom de l'etudiant : 
Notes : 0.00, -171186624640581632.00, 0.00
Moyenne generale : -57062209645182976.00 / 20
Pourcentage de reussite : -285311052520882176.00 %
=====================