✅ Solution – Labo 4.2B
🟡 Exercice 1
static void Main(string[] args)
{
double[] notes = { 70.0, 80.5, 90.0 };
double moyenne = CalculerMoyenneFinale(notes);
Console.WriteLine("Notes : " + string.Join(", ", notes));
Console.WriteLine("Moyenne : " + moyenne);
}
static double CalculerMoyenneFinale(double[] pNotes)
{
double moyenne;
moyenne = pNotes[0] * 0.3 + pNotes[1] * 0.2 + pNotes[2] * 0.5;
return moyenne;
}
🟡 Exercice 2
static void Main(string[] args)
{
double[] notes = { -3, 80.5, 90 };
double moyenne = CalculerMoyenneFinale(notes);
Console.WriteLine("Notes : " + string.Join(", ", notes));
Console.WriteLine("Moyenne : " + moyenne);
}
static double CalculerMoyenneFinale(double[] pNotes)
{
if (pNotes.Length != 3)
{
Console.WriteLine("Erreur ! Il n'y pas le bon nombre de notes !");
return 0.0;
}
if (pNotes[0] < 0.0 || pNotes[1] < 0.0 || pNotes[2] < 0.0)
{
Console.WriteLine("Erreur ! Une note n'est pas valide !");
return 0.0;
}
double moyenne;
moyenne = pNotes[0] * 0.3 + pNotes[1] * 0.2 + pNotes[2] * 0.5;
return moyenne;
}