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,bcnn:integer;
{----------------------chuong-trinh-con----------------------------}
function ucln(var n,m:integer):integer;
var i:integer;
begin
ucln:=1;
for i:=1 to n*m do
if (n mod i=0) and (m mod i=0) then
begin
if ucln<i then ucln:=i;
end;
end;
{---------------------chuong-trinh-chinh--------------------------}
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
bcnn:=a*b div ucln(a,b);
writeln('Boi chung nho nhat=',bcnn);
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.
program UocChungLonNhat;
var
a, b: integer;
function UCLN(a, b: integer): integer;
begin
if b = 0 then
UCLN := a
else
UCLN := UCLN(b, a mod b);
end;
begin
write('Nhập số nguyên dương a: ');
readln(a);
write('Nhập số nguyên dương b: ');
readln(b);
writeln('UCLN của ', a, ' và ', b, ' là ', UCLN(a, b));
end.
uses crt;
var n,i,m,max:integer;
function kt(n:integer):integer;
var j,k:integer
begin
k:=0;
for j:=2 to n do
if (n mod j)=0 then k:=k+1;
kt:=k+1;
end;
begin
readln(n);
if n=1 then write(1)
else
begin
max:=kt(2);
for m:=3 to n do
if max<kt(m) then max:=kt(m);
write(max);
end;
end.
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[50],x,n,uc,i;
//chuongtrinhcon
unsigned long long ucln(long long a,long long b)
{
if (b==0) return(a);
else return(ucln(b,a%b));
}
//chuongtrinhchinh
int main()
{
freopen("ucln.inp","r",stdin);
freopen("ucln.out","w",stdout);
cin>>n;
cin>>a[1]>>a[2];
uc=ucln(a[1],a[2]);
for (i=3; i<=n; i++)
{
cin>>x;
uc=ucln(uc,x);
}
cout<<uc;
return 0;
}
Program HOC24;
var a: array[1..32000] of integer;
ucln,i,n,ucln1: integer;
function uc(x,y: integer): integer;
var tg: integer;
begin
while y<>0 do
begin
tg:=x mod y;
x:=y;
y:=tg;
end;
uc:=x;
end;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
ucln1:=uc(a[1],a[2]);
for i:=3 to n do ucln:=uc(ucln1,a[i]);
write('Uoc chung lon nhat cua day so la: ',ucln);
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.