Переписать код с Pascal на C# - C# (204179)
Формулировка задачи:
Хочу научиться переписывать программы с Pascal на C#. Помогите литературой, а лучше на примере покажите, чтобы наглядней. Пожалуйста!!!
program Matrix53;
var
j,i,M,N,num:integer;
a: array [1..10,1..10] of real;
temp:real;
bol:boolean;
begin
// Ввод данных
writeln('Введите числа M (M<=10) и N (N<=10)');
read(M); readln(N);
writeln('Введите по ',N,' элементов (значения от 0 до 100) ');
for i:=1 to M do begin
write(i,' строки : ');
for j:=1 to N do read(a[i,j]);
end;
// Решение
Num:=0;
for i:=2 to N do
begin
bol:=true;
for j:=1 to M do
begin
if a[j,i]<0 then bol:=false;
end;
if bol then Num:=i;
end;
if num >0 then begin
for j:=1 to M do
begin
temp:=a[j,Num];
a[j,Num]:=a[j,1];
a[j,1]:=temp;
end;
end;
// ответ
writeln;
writeln('Ответ');
for i:=1 to M do begin
writeln;
for j:=1 to N do write(a[i,j],' ');
end;
end.Решение задачи: «Переписать код с Pascal на C#»
textual
Листинг программы
using System;
class simple
{
static void Main()
{
int i, j, m, n, num;
var a = new double[10,10];
double temp;
Boolean bol;
Console.WriteLine("vvedit 4usla m(m <= 10) i n (n <= 10)");
m = Convert.ToInt32(Console.ReadLine());
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("vvedit po " + n + " elementiv (0 .. 100) ");
for(i = 1; i <= m; i++)
{
Console.Write(i + " stroku:");
for(j = 1; j <= n; j++)
a[i,j] = Convert.ToDouble(Console.ReadLine());
}
num = 0;
for(i = 2; i <= n; i++)
{
bol = true;
for(j = 1; j <= m; j++)
{
if((a[i, j] < 0))
bol = false;
}
if(bol)
num = i;
if(num > 0)
{
}
for(j = 1;j <= m; j++)
{
temp = a[j, num];
a[j, num] = a[j, 1];
a[j, 1] = temp;
}
}
Console.WriteLine();
Console.WriteLine("vidpovid");
for(i = 1; i <= m; i++)
{
Console.WriteLine();
for(j = 1; j <= n; j++)
Console.Write(a[i, j] + " ");
}
}
}