// PascalABC.NET 3.0, сборка 1164 от 11.02.2016 function gcd(a,b:integer):integer; // Нахождение НОД var i: longint; begin while b <> 0 do begin a := a mod b; i := b; b := a; a := i end; Result:=a end;
begin var a:=ReadInteger('a='); var b:=ReadInteger('b='); var nod:=gcd(a,b); if nod>1 then WritelnFormat('Дробь сократима: {0}/{1}={2}/{3}', a,b,a div nod,b div nod) else WritelnFormat('Дробь {0}/{1} несократима',a,b) end.
Var ma:array[1..n,1..n] of integer; i,j:integer; begin writeln('Matrix reading...'); for i:=1 to n do begin writeln; for j:=1 to n do readln(ma[i,j]); end; writeln('First matrix:'); for i:=1 to n do begin writeln; for j:=1 to n do begin write(ma[i,j]:4); if (ma[i,j]<-8) or (ma[i,j]>6) then ma[i,j]:=sqr(ma[i,j]); end; end; writeln; writeln('Final matrix:'); for i:=1 to n do begin writeln; for j:=1 to n do write(ma[i,j]:4); end; end.
function gcd(a,b:integer):integer;
// Нахождение НОД
var
i: longint;
begin
while b <> 0 do begin
a := a mod b;
i := b; b := a; a := i
end;
Result:=a
end;
begin
var a:=ReadInteger('a=');
var b:=ReadInteger('b=');
var nod:=gcd(a,b);
if nod>1 then
WritelnFormat('Дробь сократима: {0}/{1}={2}/{3}',
a,b,a div nod,b div nod)
else WritelnFormat('Дробь {0}/{1} несократима',a,b)
end.
Тестовое решение:
a= 23541
b= 335160
Дробь сократима: 23541/335160=59/840
Const
n=5;
Var
ma:array[1..n,1..n] of integer;
i,j:integer;
begin
writeln('Matrix reading...');
for i:=1 to n do
begin
writeln;
for j:=1 to n do
readln(ma[i,j]);
end;
writeln('First matrix:');
for i:=1 to n do
begin
writeln;
for j:=1 to n do
begin
write(ma[i,j]:4);
if (ma[i,j]<-8) or (ma[i,j]>6) then ma[i,j]:=sqr(ma[i,j]);
end;
end;
writeln;
writeln('Final matrix:');
for i:=1 to n do
begin
writeln;
for j:=1 to n do
write(ma[i,j]:4);
end;
end.
Пример ввода:
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
Пример вывода:
First matrix:
1 2 3 4 5
6 7 8 9 1
2 3 4 5 6
7 8 9 1 2
3 4 5 6 7
Final matrix:
1 2 3 4 5
6 49 64 81 1
2 3 4 5 6
49 64 81 1 2
3 4 5 6 49