Pascal to C# Convert
-
How to convert this pascal code in C# :
uses crt;
var najbl:int64;
u,pok,zad,a:longint;
l:integer;
niz:array[1..946686] of int64;
uzet:array[1..6] of boolean;
w:string;
lpl:boolean;
function abs(x:int64):int64;
begin
if x>0 then abs:=x
else abs:=-x;
end;
function num2str(y:integer):string;
begin
num2str:='';
repeat
num2str:=chr(y mod 10+48)+num2str;
y:=y div 10
until y=0;
end;
procedure inc_uzet;
var ss:byte;
begin
for ss:=1 to 6 do
uzet[ss]:=false;
end;
procedure oznaci_po_redu(s:integer);
begin
l:=0;
while (s>0) do
begin
inc(l);
if not(uzet[l]) then dec(s);
end;
uzet[l]:=true;
end;
procedure dekodiraj(i:longint);
begin
if i<7 then uzet[i]:=true
else if i<127 then begin
dekodiraj((i-7) div 4 div 5 + 1);
oznaci_po_redu((i-7) div 4 - (i-7) div 4 div 5 * 5 + 1);
end
else if i<2047 then begin
dekodiraj((i-127) div 4 div 4 + 7);
oznaci_po_redu((i-127) div 4 - (i-127) div 4 div 4 * 4 + 1);
end
else if i<25087 then begin
dekodiraj((i-2047) div 4 div 3 + 127);
oznaci_po_redu((i-2047) div 4 - (i-2047) div 4 div 3 * 3 + 1);
end
else if i<209407 then begin
dekodiraj((i-25087) div 4 div 2 + 2047);
oznaci_po_redu((i-25087) div 4 - (i-25087) div 4 div 2 * 2 + 1);
end
else begin
dekodiraj((i-209407)div 4 + 25087);
oznaci_po_redu(1);
end;
end;
procedure dekodiraj1(i:longint);
var a:longint;
begin
if i<7 then begin
uzet[i]:=true;
w:=w+num2str(niz[i]);
lpl:=false;
end
else begin
if i<127 then begin
a:=(i-7) div 4 div 5 + 1;
dekodiraj1(a);
oznaci_po_redu((i-7) div 4 - 5*(a-1)+1);
end
else if i<2047 then begin
a:=(i-127) div 4 div 4 + 7;
dekodiraj1(a);
oznaci_po_redu((i-127) div 4 - 4*(a-7)+1); -
How to convert this pascal code in C# :
uses crt;
var najbl:int64;
u,pok,zad,a:longint;
l:integer;
niz:array[1..946686] of int64;
uzet:array[1..6] of boolean;
w:string;
lpl:boolean;
function abs(x:int64):int64;
begin
if x>0 then abs:=x
else abs:=-x;
end;
function num2str(y:integer):string;
begin
num2str:='';
repeat
num2str:=chr(y mod 10+48)+num2str;
y:=y div 10
until y=0;
end;
procedure inc_uzet;
var ss:byte;
begin
for ss:=1 to 6 do
uzet[ss]:=false;
end;
procedure oznaci_po_redu(s:integer);
begin
l:=0;
while (s>0) do
begin
inc(l);
if not(uzet[l]) then dec(s);
end;
uzet[l]:=true;
end;
procedure dekodiraj(i:longint);
begin
if i<7 then uzet[i]:=true
else if i<127 then begin
dekodiraj((i-7) div 4 div 5 + 1);
oznaci_po_redu((i-7) div 4 - (i-7) div 4 div 5 * 5 + 1);
end
else if i<2047 then begin
dekodiraj((i-127) div 4 div 4 + 7);
oznaci_po_redu((i-127) div 4 - (i-127) div 4 div 4 * 4 + 1);
end
else if i<25087 then begin
dekodiraj((i-2047) div 4 div 3 + 127);
oznaci_po_redu((i-2047) div 4 - (i-2047) div 4 div 3 * 3 + 1);
end
else if i<209407 then begin
dekodiraj((i-25087) div 4 div 2 + 2047);
oznaci_po_redu((i-25087) div 4 - (i-25087) div 4 div 2 * 2 + 1);
end
else begin
dekodiraj((i-209407)div 4 + 25087);
oznaci_po_redu(1);
end;
end;
procedure dekodiraj1(i:longint);
var a:longint;
begin
if i<7 then begin
uzet[i]:=true;
w:=w+num2str(niz[i]);
lpl:=false;
end
else begin
if i<127 then begin
a:=(i-7) div 4 div 5 + 1;
dekodiraj1(a);
oznaci_po_redu((i-7) div 4 - 5*(a-1)+1);
end
else if i<2047 then begin
a:=(i-127) div 4 div 4 + 7;
dekodiraj1(a);
oznaci_po_redu((i-127) div 4 - 4*(a-7)+1);LMGTFY[^] Seriously? You dump 743 lines of Pascal in a question, and expect someone here to convert it for you? :wtf: Either find a tool to do the conversion, or convert it yourself. If you get stuck with A SPECIFIC PART of the conversion, someone here will probably be able to help. But nobody is going to convert the whole program for you!
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
How to convert this pascal code in C# :
uses crt;
var najbl:int64;
u,pok,zad,a:longint;
l:integer;
niz:array[1..946686] of int64;
uzet:array[1..6] of boolean;
w:string;
lpl:boolean;
function abs(x:int64):int64;
begin
if x>0 then abs:=x
else abs:=-x;
end;
function num2str(y:integer):string;
begin
num2str:='';
repeat
num2str:=chr(y mod 10+48)+num2str;
y:=y div 10
until y=0;
end;
procedure inc_uzet;
var ss:byte;
begin
for ss:=1 to 6 do
uzet[ss]:=false;
end;
procedure oznaci_po_redu(s:integer);
begin
l:=0;
while (s>0) do
begin
inc(l);
if not(uzet[l]) then dec(s);
end;
uzet[l]:=true;
end;
procedure dekodiraj(i:longint);
begin
if i<7 then uzet[i]:=true
else if i<127 then begin
dekodiraj((i-7) div 4 div 5 + 1);
oznaci_po_redu((i-7) div 4 - (i-7) div 4 div 5 * 5 + 1);
end
else if i<2047 then begin
dekodiraj((i-127) div 4 div 4 + 7);
oznaci_po_redu((i-127) div 4 - (i-127) div 4 div 4 * 4 + 1);
end
else if i<25087 then begin
dekodiraj((i-2047) div 4 div 3 + 127);
oznaci_po_redu((i-2047) div 4 - (i-2047) div 4 div 3 * 3 + 1);
end
else if i<209407 then begin
dekodiraj((i-25087) div 4 div 2 + 2047);
oznaci_po_redu((i-25087) div 4 - (i-25087) div 4 div 2 * 2 + 1);
end
else begin
dekodiraj((i-209407)div 4 + 25087);
oznaci_po_redu(1);
end;
end;
procedure dekodiraj1(i:longint);
var a:longint;
begin
if i<7 then begin
uzet[i]:=true;
w:=w+num2str(niz[i]);
lpl:=false;
end
else begin
if i<127 then begin
a:=(i-7) div 4 div 5 + 1;
dekodiraj1(a);
oznaci_po_redu((i-7) div 4 - 5*(a-1)+1);
end
else if i<2047 then begin
a:=(i-127) div 4 div 4 + 7;
dekodiraj1(a);
oznaci_po_redu((i-127) div 4 - 4*(a-7)+1);Don't. It may seem to fit the bill for you homework question, but blindly converting code from one language to another does not normally produce code that is any good in the destination language. Pascal is not C#, and does not use the same underlying framework. If you must, understand how it's doing whatever it is doing, and adapt the algorithms to C# in a new application. But don't try and get it translated and assume you will get a good grade: you won't. And that's ignoring that your tutor is aware this site exists and will almost certainly spot the plagiarism... Besides: that code is very, very poor - it looks like it was written by three chimpanzees who never actually spoke to each other ...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
LMGTFY[^] Seriously? You dump 743 lines of Pascal in a question, and expect someone here to convert it for you? :wtf: Either find a tool to do the conversion, or convert it yourself. If you get stuck with A SPECIFIC PART of the conversion, someone here will probably be able to help. But nobody is going to convert the whole program for you!
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Don't. It may seem to fit the bill for you homework question, but blindly converting code from one language to another does not normally produce code that is any good in the destination language. Pascal is not C#, and does not use the same underlying framework. If you must, understand how it's doing whatever it is doing, and adapt the algorithms to C# in a new application. But don't try and get it translated and assume you will get a good grade: you won't. And that's ignoring that your tutor is aware this site exists and will almost certainly spot the plagiarism... Besides: that code is very, very poor - it looks like it was written by three chimpanzees who never actually spoke to each other ...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
And, as everyone knows, Pascal code must be in all caps. :-D
-
Don't. It may seem to fit the bill for you homework question, but blindly converting code from one language to another does not normally produce code that is any good in the destination language. Pascal is not C#, and does not use the same underlying framework. If you must, understand how it's doing whatever it is doing, and adapt the algorithms to C# in a new application. But don't try and get it translated and assume you will get a good grade: you won't. And that's ignoring that your tutor is aware this site exists and will almost certainly spot the plagiarism... Besides: that code is very, very poor - it looks like it was written by three chimpanzees who never actually spoke to each other ...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
OriginalGriff wrote:
written by three chimpanzees
Chimpanzees write better code than that... :-) Maybe it was actually written by a cat walking across the keyboard?
Speed of sound - 1100 ft/sec Speed of light - 186,000 mi/sec Speed of stupid - instantaneous.
-
OriginalGriff wrote:
written by three chimpanzees
Chimpanzees write better code than that... :-) Maybe it was actually written by a cat walking across the keyboard?
Speed of sound - 1100 ft/sec Speed of light - 186,000 mi/sec Speed of stupid - instantaneous.
NotPolitcallyCorrect wrote:
Chimpanzees write better code than that... :)
They certainly do! Primate Programming(tm) Inc[^] :)
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill
-
NotPolitcallyCorrect wrote:
Chimpanzees write better code than that... :)
They certainly do! Primate Programming(tm) Inc[^] :)
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
How to convert this pascal code in C# :
uses crt;
var najbl:int64;
u,pok,zad,a:longint;
l:integer;
niz:array[1..946686] of int64;
uzet:array[1..6] of boolean;
w:string;
lpl:boolean;
function abs(x:int64):int64;
begin
if x>0 then abs:=x
else abs:=-x;
end;
function num2str(y:integer):string;
begin
num2str:='';
repeat
num2str:=chr(y mod 10+48)+num2str;
y:=y div 10
until y=0;
end;
procedure inc_uzet;
var ss:byte;
begin
for ss:=1 to 6 do
uzet[ss]:=false;
end;
procedure oznaci_po_redu(s:integer);
begin
l:=0;
while (s>0) do
begin
inc(l);
if not(uzet[l]) then dec(s);
end;
uzet[l]:=true;
end;
procedure dekodiraj(i:longint);
begin
if i<7 then uzet[i]:=true
else if i<127 then begin
dekodiraj((i-7) div 4 div 5 + 1);
oznaci_po_redu((i-7) div 4 - (i-7) div 4 div 5 * 5 + 1);
end
else if i<2047 then begin
dekodiraj((i-127) div 4 div 4 + 7);
oznaci_po_redu((i-127) div 4 - (i-127) div 4 div 4 * 4 + 1);
end
else if i<25087 then begin
dekodiraj((i-2047) div 4 div 3 + 127);
oznaci_po_redu((i-2047) div 4 - (i-2047) div 4 div 3 * 3 + 1);
end
else if i<209407 then begin
dekodiraj((i-25087) div 4 div 2 + 2047);
oznaci_po_redu((i-25087) div 4 - (i-25087) div 4 div 2 * 2 + 1);
end
else begin
dekodiraj((i-209407)div 4 + 25087);
oznaci_po_redu(1);
end;
end;
procedure dekodiraj1(i:longint);
var a:longint;
begin
if i<7 then begin
uzet[i]:=true;
w:=w+num2str(niz[i]);
lpl:=false;
end
else begin
if i<127 then begin
a:=(i-7) div 4 div 5 + 1;
dekodiraj1(a);
oznaci_po_redu((i-7) div 4 - 5*(a-1)+1);
end
else if i<2047 then begin
a:=(i-127) div 4 div 4 + 7;
dekodiraj1(a);
oznaci_po_redu((i-127) div 4 - 4*(a-7)+1);