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 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.
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.
uses crt;
var a:array[1..100]of integer;
n,k,t,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(n);
end;
for i:=n downto 1 do
write(a[i]:4);
writeln;
write('Nhap k='); readln(k);
t:=0;
for i:=1 to n do
if k mod a[i]=0 then t:=t+a[i];
writeln(t);
for i:=1 to n do
if a[i]=k then write(i:4);
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.
#include <bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
freopen("dulieu.txt","r",stdout);
freopen("ketqua.txt","w",stdout);
cin>>a>>b;
cout<<a+b;
return 0;
}
uses crt;
const fi='so.txt';
var f1:text;
a:array[1..100]of integer;
n,i:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
for i:=1 to n do
write(a[i]:4);
close(f1);
readln;
end.
Program HOC24;
var a,b,i,t: integer;
function ucln(x,y: integer): integer;
var tg:integer;
begin
while y<>0 do
begin
tg:=x mod y;
x:=y;
y:=tg;
end;
ucln:=x;
end;
begin
write('Nhap a : '); readln(a);
write('Nhap b : '); readln(b);
t:=0;
for i:=1 to ucln(a,b) do
if ucln(a,b) mod i=0 then t:=t+i;
write(t);
readln
end.
uses crt;
var a,b,t,i:integer;
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
if a<b then
begin
t:=0;
for i:=1 to a do
if (a mod i=0) and (b mod i=0) then t:=t+i;
writeln('Tong cac uoc chung cua ',a,' va ',b,' la: ',t);
end
else begin
t:=0;
for i:=1 to b do
if (a mod i=0) and (b mod i=0) then t:=t+i;
writeln('Tong cac uoc chung cua ',a,' va ',b,' la: ',t);
end;
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,dem1,dem2,t1,t2,sa,sd,vt1,vt2:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
dem1:=0;
t1:=0;
dem2:=0;
t2:=0;
for i:=1 to n do
begin
if a[i]>0 then begin inc(dem1); t1:=t1+a[i]; end;
if a[i]<0 then begin inc(dem2); t2:=t2+a[i]; end;
end;
writeln(dem1);
writeln(dem2);
writeln(t1);
writeln(t2);
for i:=1 to n do
if a[i]>0 then
begin
sd:=a[i];
vt1:=i;
break;
end;
if (dem1=0) then writeln('Khong co so duong trong day')
else writeln('So duong dau tien la: ',sd,' vi tri la: ',vt1);
for i:=1 to n do
if a[i]<0 then
begin
sa:=a[i];
vt2:=i;
break;
end;
if (dem2=0) then writeln('Khong co so am trong day')
else writeln('So am dau tien la: ',sa,' vi tri la: ',vt2);
readln;
end.
uses crt;
var a,b:array[1..100]of integer;
n,i,j,ucln:integer;
begin
clrscr;
write('Nhap so cap:'); readln(n);
for i:=1 to n do
begin
readln(a[i],b[i]);
end;
for i:=1 to n do
begin
if a[i]<b[i] then
begin
ucln:=1;
for j:=1 to a[i] do
if (a[i] mod j=0) and (b[i] mod j=0) then
begin
if ucln<j then ucln:=j;
end;
end
else begin
ucln:=1;
for j:=1 to b[i] do
if (a[i] mod j=0) and (b[i] mod j=0) then
begin
if ucln<j then ucln:=j;
end;
end;
writeln('Uoc chung lon nhat cua cap thu ',i,' la: ',ucln);
end;
readln;
end.