alcatuiți un program în pascal care convertește cifrele arabe în romane
Răspunsuri la întrebare
Din romanice in arabice:
var n:integer;
a,b,c,d,f,h,q,s,w,r:string;
begin
writeln('Numar:');
readln(n);
case n mod 10 of
1:a:='I';
2:a:='II';
3:a:='III';
4:a:='IV';
5:a:='V';
6:a:='VI';
7:a:='VII';
8:a:='VIII';
9:a:='IX';
end;
b:='X';
c:='L';
d:='C';
case n mod 100 of
10..19:q:=b+a;
20..29:q:=b+b+a;
30..39:q:=b+b+b+a;
40..49:q:='IL'+a;
50..59:q:=c+a;
60..69:q:=c+b+a;
70..79:q:=c+b+b+a;
80..89:q:=c+b+b+b+a;
90..99:q:='IC'+a;
else q:=a;
end;
s:='D';
case n mod 1000 of
100..199:f:=d+q;
200..299:f:=d+d+q;
300..399:f:=d+d+d+q;
400..499:f:='ID'+q;
500..599:f:=s+q;
600..699:f:=s+d+q;
700..799:f:=s+d+d+q;
800..899:f:=s+d+d+d+q;
900..999:f:='IM'+q;
else f:=q;
end;
w:='M';
case n mod 4000 of
1000..1999:r:=w+f;
2000..2999:r:=w+w+f;
3000..3999:r:=w+w+w+f;
else r:=f;
end;
writeln(r);
end.
Din arabe in romanice:
var a:string;
i,j,k:integer;
b:array[1..50] of integer;
s:longint;
begin
repeat
writeln('Un numar arab:');
readln(a);
k:=0;
i:=1;
while(i<=length(a))and(k=0) do
if not(a[i] in ['I','V','X','L','C','D','M'])
or (copy(a,i,4)='IIII') then k:=1
else i:=i+1;
if k=1 then writeln('Numarul este introdus incorect')
until k=0;
for i:=1 to length(a) do
case a[i] of
'I':b[i]:=1;
'V':b[i]:=5;
'X':b[i]:=10;
'L':b[i]:=50;
'C':b[i]:=100;
'D':b[i]:=500;
'M':b[i]:=1000;
end;
s:=B[1];
for i:=2 to length(a) do
begin
s:=s+b[i];
if b[i-1]<b[i] then s:=s-2*b[i-1];
end;
write(s);
readln;
end.