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,x,y:integer;
//chuongtrinhcon
function ucln(var a,b:integer):integer;
var r:integer;
begin
while b>0 do
begin
r:=a mod b;
a:=b;
b:=r;
end;
ucln:=a;
end;
//chuongtrinhchinh
begin
clrscr;
readln(a,b);
x:=a;
y:=b;
if (x>0) and (y>0) then writeln(x div ucln(a,b),' ',y div ucln(a,b));
if (x<0) and (y<0) then
begin
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
if (x<0) and (y>0) then
begin
write('-');
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
if (x>0) and (y<0) then
begin
write('-');
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
readln;
end.
uses crt;
var a,b,x,y:integer;
//chuongtrinhcon
function ucln(var a,b:integer):integer;
var r:integer;
begin
while b>0 do
begin
r:=a mod b;
a:=b;
b:=r;
end;
ucln:=a;
end;
//chuongtrinhchinh
begin
clrscr;
readln(a,b);
x:=a;
y:=b;
if (x>0) and (y>0) then writeln(x div ucln(a,b),' ',y div ucln(a,b));
if (x<0) and (y<0) then
begin
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
if (x<0) and (y>0) then
begin
write('-');
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
if (x>0) and (y<0) then
begin
write('-');
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
readln;
end.
uses crt;
var a,b,x,y:integer;
//chuongtrinhcon
function ucln(var a,b:integer):integer;
var r:integer;
begin
while b>0 do
begin
r:=a mod b;
a:=b;
b:=r;
end;
ucln:=a;
end;
//chuongtrinhchinh
begin
clrscr;
readln(a,b);
x:=a;
y:=b;
if (x>0) and (y>0) then writeln(x div ucln(a,b),' ',y div ucln(a,b));
if (x<0) and (y<0) then
begin
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
if (x<0) and (y>0) then
begin
write('-');
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
if (x>0) and (y<0) then
begin
write('-');
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a,b;
//chuongtrinhcon
long long gcd(long long a,long long b)
{
if (b==0) return(a);
return gcd(b,a%b);
}
//chuongtrinhchinh
int main()
{
cin>>a>>b;
if ((a>0 && b>0) or (a<0 && b<0)) cout<<a/gcd(a,b)<<" "<<b/gcd(a,b);
else cout<<"-"<<-a/gcd(-a,b)<<" "<<b/gcd(-a,b);
return 0;
}
Câu 1:
var i,n:integer;
s:longint;
begin
Write('n = ');readln(n)
for i:=1 to n do
s:=s+2*i+1;
write('tong la: ',s);
readln
end.
Câu 2
Bài 5:
Var b:array:[1..1000] of integer;
i,n,max:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(b[i]);
End;
Write('Cac phan tu am la: ');
For i:=1 to n dko
if b[i]<0 then write(b[i]:8);
writeln;
max:=b[1];
For i:=2 to n do
If b[i] > max then max:=b[i];
write('So lon nhat la ',max);
Readln
End.
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:4);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,dem1,dem2:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem1:=0;
dem2:=0;
for i:=1 to n do
begin
if a[i]>0 then inc(dem1);
if a[i]<0 then inc(dem2);
end;
writeln('So so nguyen duong la: ',dem1);
writeln('So so nguyen am la: ',dem2);
readln;
end.
program BaiTapMang;
var
n, i, max, min, s: longint;
a: array[1..100] of integer;
begin
// Nhập số phần tử của mảng
write('Nhap so phan tu cua mang: ');
readln(n);
// Nhập giá trị từng phần tử của mảng
for i := 1 to n do
begin
write('Nhap gia tri phan tu thu ', i, ': ');
readln(a[i]);
end;
// Xuất mảng theo chiều ngang
writeln('Mang vua nhap la:');
for i := 1 to n do
write(a[i], ' ');
// Tìm giá trị lớn nhất và nhỏ nhất của mảng
max := a[1];
min := a[1];
for i := 2 to n do
begin
if a[i] > max then
max := a[i];
if a[i] < min then
min := a[i];
end;
writeln;
writeln('Gia tri lon nhat cua mang la: ', max);
writeln('Gia tri nho nhat cua mang la: ', min);
// Tính tổng các phần tử âm của mảng
s:= 0;
for i := 1 to n do
begin
if a[i] < 0 then
s:= s + a[i];
end;
writeln('Tong cac phan tu am cua mang la: ', s);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
int n,x,i,cnt,res;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>cnt;
for(i=0;i<n;i++)
{
cin>>x;
if(x%cnt==0) res++;
}
cout<<"so luong phan tu chia het cho "<<cnt<<" la: "<<res;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int gh=1000;
int n,x,i,cnt,res,dem[gh];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>cnt;
for(i=0;i<n;i++)
{
cin>>x;
if(x%cnt==0) { res++; dem[res]=x;}
}
cout<<"so luong phan tu chia het cho "<<cnt<<" la: "<<res;
cout<<"\n"<<"cac phan tu do la: "<<"\n";
for(i=1;i<=res;i++)
cout<<dem[i]<<" ";
return 0;
}
// đây mới đúng mik đọc lỗi đề nha bạn!!
uses crt;
var a,b,x,y:integer;
//chuongtrinhcon
function ucln(var a,b:integer):integer;
var r:integer;
begin
while b>0 do
begin
r:=a mod b;
a:=b;
b:=r;
end;
ucln:=a;
end;
//chuongtrinhchinh
begin
clrscr;
readln(a,b);
x:=a;
y:=b;
if (x>0) and (y>0) then writeln(x div ucln(a,b),' ',y div ucln(a,b));
if (x<0) and (y<0) then
begin
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
if (x<0) and (y>0) then
begin
write('-');
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
if (x>0) and (y<0) then
begin
write('-');
x:=abs(x);
y:=abs(y);
a:=abs(a);
b:=abs(b);
writeln(x div ucln(a,b),' ',y div ucln(a,b));
end;
readln;
end.