Перевод с паскаля на с# - C# (205888)
Формулировка задачи:
Program Insert;
const N=10;
type Element = integer;
Arr = array [0..N] of Element;
var A: Arr;
i, j: integer;
x: Element;
function Key(b: Element): integer;
begin
Key := b
end;
begin
writeln('Введите элементы массива:');
for i:=1 to N do
readln(A[i]);
for i:=2 to N do
begin
x:=A[i];
A[0] := x;
j := i-1;
while Key(x) < Key(A[j]) do
begin
A[j+1] := A[j];
j := j-1
end;
A[j+1] := x
end;
writeln('Отсортированный массив:');
for i:=1 to N do
writeln(A[i]);
end.
Тогда хоть скажите в чем ошибка
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication120
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[0];
const int arrSize1 = 11;
int i,x,j;
arr = new int[arrSize1];
for (i = 1; i < arrSize1; i++)
{
try
{
Console.Write("Введите " + i + "й элемент массива: ");
arr[i] = Convert.ToInt32(Console.ReadLine());
}
catch (FormatException)
{
Console.Write("Ошибка при вводе \n");
i--;
}
}
for (i = 1; i < arrSize1; i++)
{
Console.Write(arr[i] + " ");
}
Console.WriteLine();
for (i = 2; i < arrSize1; i++)
{
x = arr[i];
arr[0] = x;
j=i-1;
do
{
arr[j + 1] = arr[j];
j = j - 1;
}
while (x < j);
arr[j+1]=x;
}
Console.WriteLine("Отсортированный массив: ");
for (i=1; i<arrSize1; i++)
{
Console.Write(" " + arr[i]);
}
}
}
}Решение задачи: «Перевод с паскаля на с#»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication120
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[0];
const int arrSize1 = 10;
int i,L,R,j, bar,w;
arr = new int[arrSize1];
for (i = 0; i < arrSize1; i++)
{
try
{
Console.Write("Введите " + (i+1) + "-й элемент массива: ");
arr[i] = Convert.ToInt32(Console.ReadLine());
}
catch (FormatException)
{
Console.Write("Ошибка при вводе \n");
i--;
}
}
arr = QuickSort(0,arrSize1-1,arr);
for (i = 0; i < arrSize1; i++)
{
Console.Write(arr[i] + " ");
}
Console.WriteLine();
}
}
}
int[] QuickSort(int L, int R, int[] arr)
{
int i = L;
int j = R;
int bar=arr[(L+R)/2];
do
{
while (arr[i]<bar)
{
i++;
}
while(arr[j]>bar)
{
j--;
}
if (i<=j)
{
w=arr[i];
arr[i]=arr[j];
arr[j]=w;
i++;
j--;
}
} while (i<j)
if(i<R) QuickSort(i,R,arr);
if(j>L) QuickSort(L,j,arr);
return arr;
}