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.
Câu 1:
uses crt;
var st:string;
i,dem,d:integer;
vt:array[1..255]of integer;
begin
clrscr;
write('Nhap xau:'); readln(st);
d:=length(st);
dem:=0;
for i:=1 to d do
if st[i]=' ' then
begin
inc(dem);
vt[dem]:=i;
end;
writeln('So luong ki tu trang la: ',dem);
write('Vi tri:');
for i:=1 to dem do
write(vt[i]:4);
readln;
end.
Câu 2:
uses crt;
var st:string;
i,dem,d:integer;
vt:array[1..255]of integer;
begin
clrscr;
write('Nhap xau:'); readln(st);
d:=length(st);
dem:=0;
for i:=1 to d do
if st[i]<>' ' then
begin
inc(dem);
vt[dem]:=i;
end;
writeln('So luong ki tu khac ki tu trang la: ',dem);
write('Vi tri:');
for i:=1 to dem do
write(vt[i]:4);
readln;
end.
Câu 3:
uses crt;
var a:array[1..50]of integer;
n,i,max,min:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (0<n) and (n<=50);
for i:=1 to n do
begin
repeat
write('A[',i,']='); readln(a[i]);
until (0<=a[i]) and (a[i]<=32767);
end;
writeln('Day so ban vua nhap la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('Vi tri cua gia tri lon nhat la: ');
for i:=1 to n do
if max=a[i] then write(i:4);
writeln;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln('Vi tri cua gia tri nho nhat la: ');
for i:=1 to n do
if min=a[i] then write(i:4);
readln;
end.
*Đoạn lệnh :
a.
for i:=1 to n do if a[i]>0 then inc(d);
write(d);
b. t:=0;
for i:=1 to n do if a[i] mod 2=0 then t:=t+a[i];
write(t);
c.
+Vị trí lẻ:
for i:=1 to n do if a[i] mod 2=1 then write(i,' ');
+Vị trí chẵn:
for i:=1 to n do if a[i] mod 2=0 then write(i,' ');
d. max:=0;
for i:=1 to n do if a[i]>max then max:=a[i];
write(max);
e.
for i:=1 to n do
for j:=i to n do
if a[i]<a[j] then
begin
tg:=a[i];
a[i]:=a[j];
a[j]:=tg;
end;
f.
For i:=1 to n do if a[i]=k then write(i,' ');
chị @Nguyễn Minh Lệ thì viết một phần gợi ý cho bạn thôi, còn mình sẽ viết hết cả bài cho bạn
uses crt;
var dem2,n,i,dem,t,ln,tam,k,kt,dem1,j:integer;
a,b,vt:array[1..100]of integer;
begin
clrscr;
write('nhap n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------cau-a-----------------------}
dem:=0;
for i:=1 to n do
if a[i]>0 then dem:=dem+1;
writeln('so cac phan tu nguyen duong co trong mang la: ',dem);
{-------------------cau-b-----------------------------}
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln('tong cac phan tu chan co trong day la: ',t);
{-------------------cau-c-----------------------------}
writeln('cac so le co trong day la: ');
for i:=1 to n do
if a[i] mod 2=1 then write(a[i]:4);
writeln;
writeln('vi tri cac so le co trong day la: ');
for i:=1 to n do
if a[i] mod 2=1 then write(i:4);
writeln;
{-----------------cau-d--------------------------------}
ln:=a[1];
for i:=1 to n do
if ln<a[i] then ln:=a[i];
writeln('so lon nhat co trong day la: ',ln);
{----------------cau-e--------------------------------}
b[1]:=a[1];
dem1:=0;
for i:=1 to n do
begin
dem1:=dem1+1;
b[dem1]:=a[i];
end;
writeln('day tang dan cua A la: ');
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;
for i:=1 to n do
write(a[i]:4);
{-------------------------cau-f-------------------------}
writeln;
write('nhap so k: '); readln(k);
kt:=0;
dem2:=0;
for i:=1 to dem1 do
if b[i]=k then
begin
kt:=1;
dem2:=dem2+1;
vt[dem2]:=i;
end;
if kt=0 then writeln(k,' khong co trong day')
else begin
writeln(k,' co trong day A tai cac vi tri lan luot la: ');
for i:=1 to dem2 do
write(vt[i]:4);
end;
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,k,dem:integer;
begin
clrscr;
write('nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('nhap k='); readln(k);
dem:=0;
for i:=1 to n do
if a[i] mod k=0 then inc(dem);
writeln('Trong day co ',dem,' so chia het cho ',k);
readln;
end.
uses crt;
var a:array[1..20]of integer;
i,j,tam,t,max,min:integer;
begin
clrscr;
for i:=1 to 20 do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Cac so le la: ');
for i:=1 to 20 do
if a[i] mod 2<>0 then write(a[i]:6);
writeln;
write('Cac so chan la: ');
for i:=1 to 20 do
if a[i] mod 2=0 then write(a[i]:6);
writeln;
t:=0;
for i:=1 to 20 do
t:=t+a[i];
writeln('Tong cua day so la: ',t);
max:=a[1];
min:=a[1];
for i:=1 to 20 do
begin
if max<a[i] then max:=a[i];
if min>a[i] then min:=a[i];
end;
write('Vi tri cua so nho nhat la: ');
for i:=1 to 20 do
if min=a[i] then write(i:4);
writeln;
write('Vi tri cua so lon nhat la: ');
for i:=1 to 20 do
if max=a[i] then write(i:4);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,k,dem:integer;
begin
clrscr;
write('nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap k='); readln(k);
dem:=0;
for i:=1 to n do
if a[i]<>k then inc(dem);
writeln('So luong cac phan tu trong day khong bang ',k,' la: ',dem);
readln;
end.
Bài test cho các bạn tham gia tích cực tại môn Tin học .
♛๖ۣۜEɗωαɾɗ ๖ۣۜNεω๖ۣۜGαтε♛ ; Nguyễn Lê Phước Thịnh ; @Luân Trần
const fi='tvh.inp';
fo='tvh.out';
var n,d,dem,sl,s2cs,s3cs,s4cs,s5cs,s6cs,s7cs,k,i,d1:longint;
st,st1,stk:string;
f1,f2:text;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n,k);
str(n,st);
d:=length(st);
case d of
1: write(9);
2: begin
sl:=n-9;
dem:=9+sl*2;
end;
3: begin
s2cs:=(99-10)+1;
s3cs:=n-99;
dem:=9+s2cs*2+s3cs*3;
end;
4: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=n-999;
dem:=9+s2cs*2+s3cs*3+s4cs*4;
end;
5: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=n-9999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5;
end;
6: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=(99999-10000)+1;
s6cs:=n-99999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5+s6cs*6;
end;
7: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=(99999-10000)+1;
s6cs:=(999999-1000000)+1;
s7cs:=n-999999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5+s6cs*6+s7cs*7;
end;
end;
if k<=dem then
begin
i:=1;
d1:=0;
repeat
str(i,st1);
d1:=d1+length(st1);
i:=i+1;
until d1>=k;
stk:=st1[length(st1)-(d1-k)];
writeln(f2,stk);
end;
close(f1);
close(f2);
end.
Program HOC24;
var d,tg,max,j,min,i,n: integer;
t1,t: longint;
a: array[1..32000] of integer;
begin
readln(n);
for i:=1 to n do read(a[i]);
readln;
t:=0; t1:=0; max:=0; min:=32000; d:=0;
for i:=1 to n do
begin
if a[i]<0 then t:=t+a[i];
if a[i] mod 2=0 then
begin
t1:=t1+a[i];
d:=d+1;
end;
if min>a[i] then min:=a[i];
if max<a[i] then max:=a[i];
end;
for i:=1 to n do
for j:=i to n do
if a[i]>a[j] then
begin
tg:=a[i];
a[i]:=a[j];
a[j]:=tg;
end;
writeln('Tong cac so am cua day la : ',t);
writeln('Tong cac so chan la : ',t1,'; Trung binh cong cua no la : ',t1/d:2:2);
writeln('Phan tu co gia tri lon nhat la : ',max);
writeln('Phan tu co gia tri nho nhat la : ',min);
for i:=1 to n do write(a[i],' ');
readln
end.
uses crt;
var a:array[1..100]of integer;
n,i,t,j,tam,max:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Day so ban vua nhap la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cua day so la: ',t);
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 so duoc sap xep tang dan la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
max:=a[1];
for i:=2 to n do
if max<a[i] then max:=a[i];
writeln('Gia tri lon nhat la: ',max);
readln;
end.