Function NOD(a, b: Integer): Integer; Var tmp, r: Integer; Begin If b > a Then Begin tmp := a; a := b; b := tmp; End; tmp := a; While tmp > 0 Do Begin Result := tmp; tmp := tmp - b; End; End;
Пример программы с использованием данной функции:
Program Example; Var a, b: Integer;
Function NOD(a, b: Integer): Integer; Var tmp, r: Integer; Begin If b > a Then Begin tmp := a; a := b; b := tmp; End; tmp := a; While tmp > 0 Do Begin Result := tmp; tmp := tmp - b; End; End;
Var tmp, r: Integer;
Begin
If b > a Then
Begin
tmp := a;
a := b;
b := tmp;
End;
tmp := a;
While tmp > 0 Do
Begin
Result := tmp;
tmp := tmp - b;
End;
End;
Пример программы с использованием данной функции:
Program Example;
Var a, b: Integer;
Function NOD(a, b: Integer): Integer;
Var tmp, r: Integer;
Begin
If b > a Then
Begin
tmp := a;
a := b;
b := tmp;
End;
tmp := a;
While tmp > 0 Do
Begin
Result := tmp;
tmp := tmp - b;
End;
End;
Begin
Write('a = ');
ReadLn(a);
Write('b = ');
ReadLn(b);
Write('НОД: ', NOD(a, b));
ReadLn;
End.