Informatică, întrebare adresată de aryanaa14, 8 ani în urmă

descrie un algoritm care calculeaza cel mai mic multiplu comun a doua numere date

Răspunsuri la întrebare

Răspuns de grigore2018
4

Răspuns:

var

 A, B, x, y, N: integer;

begin

 writeln('Enter A si B:');

 readln(A, B);

 x := A;  

 y := B;  

 write('Rezultat: CMMMC(', A, ', ', B, ') = ');

 while A <> B do

   if A > B then A := A - B  

   else B := B - A;  

 N := x * (y div A);  

 writeln(' ', N)

end.

Functiei:

var

x, y: integer;

 

function CC(x, y: integer): integer;

begin

if x<>0 then CC:=CC(y mod x, x)  

 else CC:=y;

end;

 

function CCD(x, y: integer): integer;

begin

CCD:=(x div CC(x,y))*y;

end;

 

begin

read(x, y);

write(CCD(x, y));

end.

Alte întrebări interesante