Перевести из паскаля в си шарп - C#
Формулировка задачи:
Помогите перевести из паскаля вот этот код
uses
CRT;
const
n = 10;
type
student = record
name: string[30];
group: integer;
ses: array[1..5] of byte;
end;
var
stud1: array[1..N] of student;
tmp: student;
st, i: integer;
fl: boolean;
begin
for st := 1 to N do
begin
write('Input first name: ');
readln(stud1[st].name);
write('Input number of group: ');
readln(stud1[st].group);
for i := 1 to 5 do
begin
write('Input ', i, ' mark: ');
readln(stud1[st].ses[i]);
end;
end;
for st := 1 to n - 1 do
for i := st + 1 to n do
if stud1[st].name > stud1[i].name then
begin
tmp := stud1[st];
stud1[st] := stud1[i];
stud1[i] := tmp;
end;
fl := true;
for st := 1 to n do
begin
i := 1;
while (i <= 5) and (stud1[st].ses[i] <> 2) do
inc(i);
if (i <= 5) then
begin
fl := false;
writeln('Student ', stud1[st].name, ' (group ', stud1[st].group, ') have mark 2');
end;
end;
if fl then
writeln('No students, which have mark 2');
readln;
end.Решение задачи: «Перевести из паскаля в си шарп»
textual
Листинг программы
namespace ConsoleApplication1
{
class Program
{
const int n = 10;
struct student
{
internal string name;
internal int group;
internal byte[] ses;
}
static void Main(string[] args)
{
student[] stud1 = new student[n];
student tmp = new student();
bool fl;
for (int st = 0; st < n; st++)
{
Console.WriteLine("Input first name: ");
stud1[st].name = Console.ReadLine();
stud1[st].group = 0;
while (stud1[st].group == 0)
{
Console.WriteLine("IInput number of group: ");
int.TryParse(Console.ReadLine(), out stud1[st].group);
}
stud1[st].ses = new byte[5];
for (int i = 0; i < 5; i++)
{
stud1[st].ses[i] = 0;
while (stud1[st].ses[0] == 0)
{
Console.WriteLine("Input {0} mark: ", i);
byte.TryParse(Console.ReadLine(), out stud1[st].ses[i]);
}
}
}
for (int st = 0; st < n-1; st++)
{
for (int i = st + 1; i < n; i++)
{
if (stud1[st].name.CompareTo(stud1[i].name)>0)
{
tmp = stud1[st];
stud1[st] = stud1[i];
stud1[i] = tmp;
}
}
}
fl = true;
for (int st = 0; st < n; st++)
{
int i = 0;
while ((i < 5) && (stud1[st].ses[i] != 2))
i++;
if (i < 5)
{
fl = false;
Console.WriteLine("Student {0} (group {1}) have mark 2", stud1[st].name, stud1[st].group);
}
}
if (fl)
Console.WriteLine("No students, which have mark 2");
Console.ReadLine();
}
}
}