Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp19
- {
- class Program
- {
- struct Students
- {
- public string Name;
- public int[] Exams;
- public double ExamMedium;
- public Students(string Name)
- {
- this.Name = Name;
- Exams = new int[5];
- ExamMedium = 0;
- }
- }
- static void ExamsMedium(ref Students[,] sd)
- {
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- for (int k = 0; k < 5; k++)
- sd[i, 0].ExamMedium += Convert.ToDouble(sd[i, j].Exams[k]);
- }
- sd[i, 0].ExamMedium /= 5;
- for (int j = 0; j < 5; j++)
- sd[i, j].ExamMedium = sd[i, 0].ExamMedium;
- }
- }
- static void StudentsWrite(Students[,] sd)
- {
- int[] arr = new int[3] { 0, 1, 2 };
- for (int i = 0; i < 3 - 1; i++)
- {
- for (int j = 0; j < 3 - i - 1; j++)
- {
- if (sd[j, 0].ExamMedium > sd[j + 1, 0].ExamMedium)
- {
- // меняем элементы местами
- int temp = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = temp;
- }
- }
- }
- for (int i = 0; i < 3; i++)
- {
- int q = arr[i];
- Console.WriteLine("{0}я группа со средним баллом {1}", i + 1, sd[q, 0].ExamMedium);
- for (int j = 0; j < 5; j++)
- {
- Console.Write(" {0}, оценки:", sd[q, j].Name);
- for (int k = 0; k < 5; k++)
- {
- Console.Write(" {0}", sd[q, j].Exams[k]);
- }
- Console.WriteLine();
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- Students[,] students = new Students[3, 5];
- string[,] names = new string[3, 5] { { "Петров", "Иванов", "Сидоров", "Лапенко", "Ребров" },
- { "Римин", "Легков", "Капица", "Смирнов", "Савенко" },
- { "Лазарев", "Спивак", "Юдин", "Батейко", "Рыбаков" } };
- for (int i = 0; i < 3; i++)
- for (int j = 0; j < 5; j++)
- {
- students[i, j].Name = names[i, j];
- Random rand = new Random();
- students[i, j].Exams = new int[] { rand.Next(2, 5), rand.Next(2, 5), rand.Next(2, 5), rand.Next(2, 5), rand.Next(2, 5) };
- }
- ExamsMedium(ref students);
- StudentsWrite(students);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement