Using System;
namespace Znanija {
internal class Program {
private static void Main() {
var r = new Random(DateTime.Now.Millisecond);
var course = r.Next(1, 6);
var students = new int[5,8];
for (var i = 0; i < students.GetLength(0); i++) {
for (var j = 0; j < students.GetLength(1); j++) {
students[i, j] = r.Next(10, 40);
Console.Write("{0:d2} ", students[i, j]);
}
Console.WriteLine();
}
Console.WriteLine("На курсе {0} кол-во студентов = {1}", course, CountStudents(students, course));
Console.ReadKey();
}
private static int CountStudents(int[,] students, int course) {
if (students.GetLength(0) < course) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Нет курса " + course);
return 0;
}
var number = 0;
for (var i = 0; i < students.GetLength(0); i++) {
number += students[course - 1, i];
}
return number;
}
}
}