Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
uses crt;
var a,b,ucln,bcnn,i:integer;
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
ucln:=1;
if a<b then begin
for i:=1 to a do
if (a mod i=0) and (b mod i=0) then begin
if ucln<i then ucln:=i;
end;
end else begin
for i:=1 to b do
if (a mod i=0) and (b mod i=0) then
begin
if ucln<i then ucln:=i;
end;
end;
bcnn:=a*b;
for i:=a*b-1 downto 1 do
if (i mod a=0) and (i mod b=0) then
begin
if bcnn>i then bcnn:=i;
end;
writeln('Uoc chung lon nhat la: ',ucln);
writeln('Boi chung nho nhat la: ',bcnn);
readln;
end.
Câu 1:
uses crt;
var m,n,ucln,i:integer;
begin
clrscr;
write('Nhap m='); readln(m);
write('Nhap n='); readln(n);
ucln:=1;
if m<n then
begin
for i:=1 to m do
if (m mod i=0) and (n mod i=0) then
begin
if ucln<i then ucln:=i;
end;
end
else begin
for i:=1 to n do
if (m mod i=0) and (n mod i=0) then
begin
if ucln<i then ucln:=i;
end;
end;
writeln(ucln);
readln;
end.
Câu 2:
uses crt;
var m,n,bcnn,i:integer;
begin
clrscr;
write('Nhap m='); readln(m);
write('Nhap n='); readln(n);
bcnn:=m*n;
for i:=m*n-1 downto 1 do
if (i mod m=0) and (i mod n=0) then
begin
if bcnn>i then bcnn:=i;
end;
writeln(bcnn);
readln;
end.
a)
program UCLN_va_BCNN;
uses crt;
var a,b,c,r,p:integer;
begin
clrscr;
write('nhap a,b:');readln(a,b);
if a<b then
begin
c:=a;
a:=b;
b:=c;
end;
p:=a*b;
r:=a mod b;
while r<>0 do
begin
a:=b;
b:=r;
r:=a mod b;
end;
writeln('UCLN la: ',b);
writeln('BCNN la: ',p div b);
readln;
end.
b)
program fibonaci;
uses crt;
var i,n:integer;
a:array[1..30]of integer;
begin
clrscr;
repeat
write('nhap n:');readln(n);
if (n<1)or(n>30) then writeln('so n phai lon hon hoac bang 1 va nho hon hoac bang 30:);
until (n>=1)and(n<=30);
a[1]:=1;
a[2]:=1;
for i:=3 to n do
a[i]:=a[i-1]+a[i-2];
writeln(n,' so fibonaci dau tien la:');
for i:=1 to n do
write(a[i]:3);
readln;
end.
int BCNN(int a, int b)
{
int result = UCLN(a, b);
return a * b / result;
}
int main()
{
int a, b; cout << "a = ";
cin >> a;
cout << "b = ";
cin >> b;
int result = UCLN(a, b);
cout << "UCLN : "<<result; cout << "\n";
result = BCNN(a, b);
cout << "BCNN : " << result << endl;
system("pause");
}
Biết viết mỗi C++, Pascal thì miss gần hết :(
uses crt;
var a,b,bcnn,i:longint;
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
bcnn:=a*b;
for i:=a*b-1 downto 1 do
if (i mod a=0) and (i mod b=0) then
begin
if bcnn>i then bcnn:=i;
end;
writeln('Boi chung nho nhat la: ',bcnn);
readln;
end.