Skip to content

Instantly share code, notes, and snippets.

@jpolivra
Last active October 18, 2023 22:29
Show Gist options
  • Save jpolivra/b0e651880b4dbf4a6f6474f01df1454e to your computer and use it in GitHub Desktop.
Save jpolivra/b0e651880b4dbf4a6f6474f01df1454e to your computer and use it in GitHub Desktop.
Given 5 students, get them grades taking in care that 3 tests were applied. Then calculate the classroom arithmetic mean and each student total grade.
namespace abstract_data_types;
class Program
{
static void Main(string[] args)
{
double[,] StudentsGrades = new double[5, 3];
for(int i = 0; i < 5; i++)
{
Console.WriteLine($"Input the grades of the student number {i + 1}: ");
for(int j = 0; j < 3; j++)
{
Console.Write($"Test number {j + 1} grade: ");
StudentsGrades[i, j] = double.Parse(Console.ReadLine());
}
}
double StudentsGradesArithmeticMean = GetArithmeticMean(StudentsGrades);
Console.WriteLine($"The classroom grades arithmetic mean is: {StudentsGradesArithmeticMean}");
// Students total grade
for(int i = 0; i < 5; i++)
{
double Total = 0.0;
for(int j = 0; j < 3; j++)
{
Total += StudentsGrades[i, j] ;
if(j == 2) {
Console.WriteLine($"Test student number {i + 1} total grade is: {Total}");
}
}
}
}
// Methods
static double GetArithmeticMean(double[,] StudentsGrades)
{
double Mean = 0.0;
for(int i = 0; i < 5; i++)
{
double TemporaryMean = 0.0;
for(int j = 0; j < 3; j++)
{
TemporaryMean += StudentsGrades[i, j] ;
if(j == 2) {
Mean = TemporaryMean / 3;
}
}
}
return Mean;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment