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 TimSoLonHonA;
var
a: array of integer;
n, i, x: integer;
begin
write('Nhap so phan tu cua day so: ');
readln(n);
SetLength(a, n);
for i := 0 to n - 1 do
begin
write('Nhap gia tri phan tu thu ', i + 1, ': ');
readln(a[i]);
end;
write('Nhap vao mot so nguyen bat ky: ');
readln(x);
writeln('Cac so lon hon ', x, ' la: ');
for i := 0 to n - 1 do
begin
if (a[i] > x) then
writeln(a[i]);
end;
end.
1)
var a,b : integer;
begin
writeln('nhap a va b =');
readln(a,b);
if a>b then writeln('So lon hon la a') else writeln('so lon hon la b');
if a=b then writeln('a va b bang nhau');
readln
end.
Câu 1:
uses crt;
var n,i,dem,j,kt1,kt2,a,b,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
dem:=0;
if n mod 2=1 then
begin
a:=2;
b:=n-a;
kt:=0;
for i:=2 to trunc(sqrt(b)) do
if b mod i=0 then kt:=1;
if kt=0 then inc(dem);
end
else begin
for i:=2 to n div 2 do
begin
a:=i;
b:=n-i;
kt1:=0;
kt2:=0;
for j:=2 to trunc(sqrt(a)) do
if a mod j=0 then kt1:=1;
for j:=2 to trunc(sqrt(b)) do
if b mod j=0 then kt2:=1;
if (kt1=0) and (kt2=0) then inc(dem);
end;
end;
writeln('So cach phan tich ',n,' thanh tong hai so nguyen to la: ',dem);
readln;
end.
Câu 2:
uses crt;
var n,x:integer;
{-----------------ham-kiem-tra-nguyen-to-----------------}
function ktnt(x:integer):boolean;
var kt:boolean;
i:integer;
begin
kt:=true;
for i:=2 to trunc(sqrt(x)) do
if x mod i=0 then
begin
kt:=false;
break;
end;
if kt=true then ktnt:=true
else ktnt:=false;
end;
{---------------ham-kiem-tra-so-doi-xung---------------}
function ktdx(x:integer):boolean;
var kt:boolean;
d,i:integer;
st:string;
begin
str(x,st);
d:=length(st);
kt:=true;
for i:=1 to d do
if st[i]<>st[d-i+1] then
begin
kt:=false;
break;
end;
if kt=true then ktdx:=true
else ktdx:=false;
end;
{--------------chuong-trinh-chinh---------------}
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n>0;
if (ktnt(n)=true) and (ktdx(n)=true) then writeln(n,' la so nguyen to doi xung')
else writeln(n,' khong la so nguyen to doi xung');
x:=n+1;
repeat
x:=x+1;
until (ktnt(x)=true) and (ktdx(x)=true);
writeln('So nguyen to doi xung nho nhat lon hon ',n,' la: ',x);
readln;
end.
Bài 1:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
for i:=1 to n do
if i mod 6=0 then s:=s+i;
writeln(s);
readln;
end.
Bài 2:
uses crt;
var a,b,c,ucln,i:integer;
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
write('c='); readln(c);
while a<>b do
begin
if a>b then a:=a-b
else b:=b-a;
end;
ucln:=a;
while ucln<>c do
begin
if ucln>c then ucln:=ucln-c
else c:=c-ucln;
end;
writeln(ucln);
readln;
end.
a)
uses crt;
var n,i,kt,j:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n>1;
writeln('Cac so nguyen to be hon hoac bang ',n,' la: ');
for i:=2 to n do
begin
kt:=0;
for j:=2 to i-1 do
if i mod j=0 then kt:=1;
if kt=0 then write(i:4);
end;
readln;
end.
refer
uses crt;
var a:array[1..100]of integer;
n,i,max,min:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
max:=a[1];
min:=a[1];
for i:=1 to n do
begin
if max<a[i] then max:=a[i];
if min>a[i] then min:=a[i];
end;
writeln('Vi tri cua so lon nhat la: ');
for i:=1 to n do
if max=a[i] then write(i:4);
writeln;
writeln('Vi tri cua so nho nhat la: ');
for i:=1 to n do
if min=a[i] then write(i:4);
readln;
#include <bits/stdc++.h>
using namespace std;
int A[100],B[100],C[100],kt,n,nn,dem1=0, dem2=0;
int main()
{
cin>>n;
for (int i=1; i<=n; i++)
cin>>A[i];
kt=0;
nn=INT_MAX;
for (int i=1; i<=n; i++)
if (A[i]%2!=0)
{
kt=1;
if (nn>=A[i]) nn=A[i];
}
if (kt==0) cout<<"khong co";
else cout<<nn;
cout<<endl;
for (int i=1; i<=n; i++)
if (A[i]%2==0 && A[i]>7)
cout<<A[i]<<" ";
cout<<endl;
for (int i=1; i<=n; i++)
if (A[i]%2!=0)
{
dem1++;
B[dem1]=A[i];
}
for (int i=1; i<=n; i++)
if (A[i]%2==0)
{
dem2++;
C[dem2]=A[i];
}
sort(B,B+dem1+1);
sort(C,C+dem2+1);
for (int i=dem1; i>=1; i--)
cout<<B[i]<<" ";
for (int i=1; i<=dem2; i++)
cout<<C[i]<<" ";
}
program TimMinMaxTrungBinh;
var
N, i, max, min, sum: integer;
a: array[1..50] of integer;
TB, minTB, maxTB: real;
begin
writeln('Nhap so nguyen duong N:');
readln(N);
sum := 0;
for i := 1 to N do
begin
write('Nhap so thu ', i, ': ');
readln(a[i]);
sum := sum + a[i];
end;
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;
TB := sum / N;
minTB := TB;
maxTB := TB;
for i := 1 to N do
begin
if (a[i] < TB) and (a[i] < minTB) then
minTB := a[i];
if (a[i] > TB) and (a[i] > maxTB) then
maxTB := a[i];
end;
writeln('Gia tri lon nhat la: ', max);
writeln('Gia tri nho nhat la: ', min);
writeln('Gia tri trung binh la: ', TB:2:2);
if minTB = TB then
writeln('Khong co gia tri nao nho hon TB')
else
writeln('Gia tri nho nhat < TB la: ', minTB);
if maxTB = TB then
writeln('Khong co gia tri nao lon hon TB')
else
writeln('Gia tri lon nhat > TB la: ', maxTB);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,x,y;
cout<<"Nhap n="; cin>>n;
x=n;
y=n+1;
if (x%2==0) cout<<x-2<<endl;
else cout<<x-1<<endl;
if (y%5==0) cout<<y;
else {
while (y%5!=0)
y++;
cout<<y;
}
return 0;
}