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.
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.
Program HOC24;
const fi='cau2.inp';
fo='cau2.out';
var dt,a,b,c: integer;
procedure ip;
begin
assign(f,fi);
reset(f);
uses crt;
var i,n,c,b,uc:integer;
bcnn:int64;
a:array[1..100] of integer;
{--------------------------chuong-trinh-con-tim-ucln-cua-hai-so---------------}
function ucln(c,b:integer):integer;
var r:integer;
begin
r:=c mod b;
while r<>0 do
begin
c:=b;
b:=r;
r:=c mod b;
end;
ucln:=b;
end;
{---------------------------chuong-trinh-chinh-----------------------------------}
begin
clrscr;
Write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
uc:=ucln(a[1],a[2]);
for i:=3 to n do
uc:=ucln(uc,a[i]);
writeln(uc);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
freopen("dulieu.txt","r",stdin);
freopen("ketqua.txt","w",stdout);
cin>>a>>b;
cout<<max(a,b);
return 0;
}
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.
Câu 2:
uses crt;
var a,b:integer;
{-----------------chuong-trinh-con-------------------}
function ucln(x,y:integer):integer;
var i,uc:integer;
begin
if x<y then
begin
uc:=1;
for i:=1 to x do
if (x mod i=0) and (y mod i=0) then
begin
if uc<i then uc:=i;
end;
end
else begin
uc:=1;
for i:=1 to y do
if (x mod i=0) and (y mod i=0) then
begin
if uc<i then uc:=i;
end;
end;
ucln:=uc;
end;
{--------------------------chuong-trinh-chinh------------------------}
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
writeln(a,'/',b,'=',a div ucln(a,b),'/',b div ucln(a,b));
readln;
end.
Câu 1:
const fi='songuyen.inp';
fo='tong.out';
var f1,f2:text;
a:array[1..100]of integer;
i,n,t:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
n:=0;
while not eoln(f1) do
begin
n:=n+1;
read(f1,a[n]);
end;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln(f2,t);
close(f1);
close(f2);
end.
const fi='bt.inp';
fo='bt.out';
var f1,f2:text;
a:array[1..100]of integer;
i,n,ln:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do read(f1,a[i]);
ln:=a[1];
for i:=1 to n do
if ln<a[i] then ln:=a[i];
write(f2,ln);
close(f1);
close(f2);
end.
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.
uses crt;
const fi='dulieu.txt';
var f1:text;
a:array[1..100]of real;
t:real;
i,n:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
readln(f1,n);
for i:=1 to n do readln(f1,a[i]);
t:=0;
for i:=1 to n do t:=t+a[i];
writeln(t);
close(f1);
readln;
end.
const fi='ucln.inp';
fo='ucln.out';
var f1,f2:text;
a,b,i,ucln:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,a,b);
if a<b then
begin
ucln:=1;
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
ucln:=1;
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;
writeln(f2,ucln);
close(f1);
close(f2);
end.