Конвертировать с Pascal на C# - C# (182468)
Формулировка задачи:
Нужно перевести этот код с Pascal на C#:
Пытался перевести, но выводит значение 116 вместо 169.
Помогите правильно перевести код. Заранее спасибо)
const
N = 9;
L = 5;
A : array [1..N] of Integer = (12,45,5,4,21,20,10,12,26);
var
min, i, j : Integer;
begin
min := A[1]*A[1] + A[1+L]*A[1+L];
for i := 1 to N-L do
for j := i+L to N do
if min > A[i]*A[i] + A[j]*A[j] then
min := A[i]*A[i] + A[j]*A[j];
WriteLn(min);
end.using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program1
{
class Program
{
static void Main(string[] args)
{
int L = 5;
int[] a = new int[9] {12, 45, 5, 4, 21, 20, 10, 12, 26};
int min;
min = a[1] * a[1] + a[1 + L] * a[1 + L];
for (int i = 1; i < a.Length - L; i++)
{
for (int j = i + L; i < a.Length; i++)
{
if (min > a[i] * a[i] + a[j] * a[j])
{
min = a[i] * a[i] + a[j] * a[j];
}
}
}
Console.WriteLine(min);
}
}
}Решение задачи: «Конвертировать с Pascal на C#»
textual
Листинг программы
const int N = 9;
const int L = 5;
int[] A = { 12, 45, 5, 4, 21, 20, 10, 12, 26 };
int min;
min = A[1] * A[1] + A[1 + L] * A[1 + L];
for (int i = 1; i < N - L; i++)
{
for (int j = i + L; j < N; j++)
{
if (min > A[i] * A[i] + A[j] * A[j])
{
min = A[i] * A[i] + A[j] * A[j];
}
}
}
Console.WriteLine(min);