uses crt; var a: array [1..300] of longint; n, temp: integer;temp2, min: longint; function UCLN(x, y: longint): longint; begin if x mod y = 0 then UCLN := y else UCLN := UCLN(y, x mod y); end; begin clrscr; Write(‘Nhap so cac so can tim UCLN: ‘); Readln(n); Write(‘Nhap cac so: ‘); repeat inc(temp); readln(a[temp]) until temp = n; min :=2000 * 2000 *2-1; repeat repeat dec(temp); temp2 := ucln(a[temp], a[n]); if temp2 < min then min := temp2 until temp = 1; dec(n); temp := n until n = 1; Writeln(‘UCLN cua cac so tren la ‘, min); Readln end.
#include<stdio.h>
int main()
{
int a,b,r;
printf(“a = “);
scanf(“%d”,&a);
printf(“b = “);
scanf(“%d”,&b);
while((r = (a%b)) != 0)
{
a = b;
b = r;
}
printf(“UCLN = %d”,b);
}
uses crt;
var a: array [1..300] of longint;
n, temp: integer;temp2, min: longint;
function UCLN(x, y: longint): longint;
begin
if x mod y = 0 then UCLN := y else UCLN := UCLN(y, x mod y);
end;
begin
clrscr;
Write(‘Nhap so cac so can tim UCLN: ‘); Readln(n);
Write(‘Nhap cac so: ‘);
repeat
inc(temp);
readln(a[temp])
until temp = n;
min :=2000 * 2000 *2-1;
repeat
repeat
dec(temp);
temp2 := ucln(a[temp], a[n]);
if temp2 < min then min := temp2
until temp = 1;
dec(n);
temp := n
until n = 1;
Writeln(‘UCLN cua cac so tren la ‘, min);
Readln
end.