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 TrungBinhCong;
const
MAX = 100;
var
danhSach: array[1..MAX] of integer;
n, i, tong: integer;
trungbinh: real;
begin
write('Nhap so ptu (toi da 100): ');
readln(n);
tong := 0;
for i := 1 to n do
begin
write('Nhap giatri ptu thu ', i, ': ');
readln(danhsach[i]);
tong := tong + danhsach[i];
end;
trungbinh := tong / n;
writeln('Tbc cua danh sach la: ', trungbinh:0:2);
readln;
end.
Var a:array[1..100] of integer;
i,n:integer;
s:longint;
tbc:real;
Begin
Repeat
Write('n = ');readln(n);
Until (n>0) and (n<=100);
For i:=1 to n do
Begin
Write('Nhap phan tu thu ',i);readln(a[i]);
s:=s+a[i];
End;
tbc:=s/n;
Write('Trung binh cong la ',tbc:10:2);
Readln
End.
Var a:array[1..100] of integer;
i,n:integer;
s:longint;
Begin
Repeat
Write('n = ');readln(n);
Until (n>0) and (n<=100);
For i:=1 to n do
Begin
Write('Nhap phan tu thu ',i);readln(a[i]);
If a[i] mod 2 = 0 then s:=s+a[i];
End;
Write('Tong cac so chan la ',s);
Readln
End.
phần đọc tự viết
for i:=j to n do
b[i+1]:=a[i];
for i:=1 to j do write(g,a[i]);
write(g,M);
for i:=j+1 to n+1 do
write(g,b[i]);
uses crt;
var a,b:array[1..100]of integer;
i,n,m,k,tam:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to n do
write(a[i]:6);
writeln;
write('Nhap m='); readln(m);
write('Nhap chi so k='); readln(k);
for i:=1 to k do
b[i]:=a[i];
for i:=k+2 to n+1 do
b[i]:=a[i-1];
b[k+1]:=m;
for i:=1 to n+1 do
write(b[i]:6);
readln;
end.
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.