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.
1)
Var array:[1..1000] of integer;
i,n,t:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do
If a[i] > a[i+1] then
Begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
End;
Write('Sap xep tang dan ');
For i:=1 to n do write(a[i]:8);
Readln
End.
2)
Var array:[1..1000] of integer;
i,n,t:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do
If a[i] < a[i+1] then
Begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
End;
Write('Sap xep giam dan ');
For i:=1 to n do write(a[i]:8);
Readln
End.
program TT;
uses CRT;
Var i,n:integer;
P:longint; S:Real;
begin
Write('Nhap N: '); Readln(N);
S:=0;
P:=1;
For i:=1 to N do
begin P:=P*i; S:=S+1/P; end;
Writeln('Tong S= ',S:5:3);
Readln
End.
Câu 1:
uses crt;
var a:array[1..10]of integer;
i,n,k,t:integer;
begin
clrscr;
write('nhap n='); readln(n);
if (0<n) and (n<=10) then
begin
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
write('nhap k='); readln(k);
{----------------------------cau-a-------------------------}
writeln('cac phan tu lon hon hoac bang ',k,' trong day la: ');
for i:=1 to n do
if a[i]>=k then write(a[i]:4);
{--------------------------cau-b-------------------------------}
writeln;
t:=0;
for i:=1 to n do
if a[i]>=k then t:=t+a[i];
writeln('tong cac phan tu lon hon hoac bang ',k,' la: ',t);
end
else writeln('vui long nhap lai');
readln;
end.
Câu 2:
uses crt;
var a:array[1..10]of integer;
i,n,tam,j,k:integer;
begim
clrscr;
write('nhap n='); readln(n);
if (0<n) and (n<=10) then
begin
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
write('nhap k='); readln(k);
writeln('Day truoc khi sap xep la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
writeln('day sap xep tang dan la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]<a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
writeln('day sap xep giam dan la: ');
for i:=1 to n do
write(a[i]:4);
end
else writeln('vui long nhap lai');
readln;
end.
Bạn thử xem cách mình làm đc ko?
___________
uses crt;
var A:array[1..1000] of integer;
n,i,tc,tl,z,j,e,tic,til,dem,d,dc,dl:integer;
begin
clrscr;
Write('Nhap n: '); readln(n);
for i:=1 to n do
begin
Write('Nhap phan tu thu ',i,' :'); readln(A[i]);
end;
i:=1;
tc:=0;
tl:=0;
for d:=1 to n do if (A[d] mod 2=0) then dc:=dc+1 else dl:=dl+1;
if (dc<>0) then tic:=1 else tic:=0;
if (dl<>0) then til:=1 else til:=0;
for i:=1 to n do if (A[i] mod 2=0) then
begin
tc:=tc+A[i];
tic:=tic*A[i];
end
else
begin
tl:=tl+A[i];
til:=til*A[i];
end;
Writeln('Tong cac phan tu chan la: ' ,tc);
Writeln('Tich cac phan tu chan la: ' ,tic);
Writeln('Tong cac phan tu le la: ' ,tl);
Writeln('Tich cac phan tu le la: ' ,til);
for e:=1 to (n-1) do
for j:=e+1 to n do
if A[e]>A[j] Then
begin
z:=A[e]; A[e]:=A[j]; A[j]:=z;
end;
Writeln('Day sau khi duoc sap xep tang dan la: ');
for dem:=1 to n do Write(A[dem],' '); writeln;
writeln('Day sau khi duoc sap xep giam dan la: ');
for dem:=n downto 1 do write(A[dem],' ');
readln;
end.
uses crt;
var a,b,c:array[1..100]of longint;
n,m,i,j,dem,tam:integer;
begin
clrscr;
{------------nhap-mang-A----------------}
write('chieu dai mang A='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{------------nhap-mang-B----------------}
write('chieu dai mang B='); readln(m);
for j:=1 to m do
begin
write('b[',j,']='); readln(b[j]);
end;
{-----------------xuat-day-A--------------------}
writeln('day A=');
for i:=1 to n do
write(a[i]:4);
{---------------xuat-day-B--------------------}
writeln;
writeln('day B=');
for j:=1 to m do
write(b[j]:4);
writeln;
{------------sap-xep-mang-A------------------}
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
writeln('day A sau khi sap xep la: ');
for i:=1 to n do write(a[i]:4);
{-----------sap-xep-mang-B------------------}
writeln;
for i:=1 to m-1 do
for j:=i+1 to m do
if b[i]>b[j] then
begin
tam:=b[i];
b[i]:=b[j];
b[j]:=tam;
end;
writeln('day B sau khi sap xep la: ');
for j:=1 to m do write(b[j]:4);
{--------------cho-cac-phan-tu-cua-A-va-B-vao-array-C------------------}
writeln;
writeln('day C=');
dem:=0;
for i:=1 to n do
begin
inc(dem);
c[dem]:=a[i];
end;
for j:=1 to m do
begin
inc(dem);
c[dem]:=b[j];
end;
for i:=1 to dem do write(c[i]:4);
{----------------sap-xep-mang-C-----------------}
for i:=1 to dem-1 do
for j:=i+1 to dem do
if c[i]>c[j] then
begin
tam:=c[i];
c[i]:=c[j];
c[j]:=tam;
end;
writeln;
writeln('day C sau khi sap xep la: ');
for i:=1 to dem do
write(c[i]:4);
readln;
end.
Var a:array[1..1000] of integer;
i,m,tam:integer;
Begin
Write('m = ');readln(m);
For i:=1 to m do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to m do
If a[i] < a[i+1] then
Begin
tam:=a[i];
a[i]:=a[i+1];
a[i+1]:=tam;
End;
Write('Mang sau khi sap xep: ');
For i:=1 to m do
Write(a[i]:8);
Readln;
End.
C2
Câu lênh dc thuc hiên nhu sau
B1 kiêm tra điêu kien
B2 neu điêu kien sai, cau lênh se bi bo qua va viêc thuc hiên lênh lap se két thuc. Neu điêu kien dung, thuc hiên cau lênh va quay lai b1
Cu phap
For( biên đêm) :=(gia tri dau) to(gia trí cuoi) do(cau lênh) ;
C2 dai lam mai len lop chép sau