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:array[1..100]of integer;
i,n,tc,tl,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
tc:=0;
tl:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then tc:=tc+a[i]
else tl:=tl+a[i];
end;
writeln('Tong cac so chan la: ',tc);
writeln('Tong cac so le la: ',tl);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cua day so la: ',t);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,min:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln(min);
readln;
end.
Bai 2:
uses crt;
var a:array[1..100]of integer;
i,n,t,nn:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
nn:=a[1];
for i:=1 to n do
if nn>a[i] then nn:=a[i];
write(nn);
readln;
end.
Câu 1:
program mangsonguyen;
var
a: array[1..100] of integer;
i, n: integer;
begin
writeln('Nhap so phan tu trong mang: ');
readln(n);
writeln('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
writeln('Mang vua nhap la:');
for i := 1 to n do
write(a[i], ' ');
end.
Câu 2:
program trungbinhcong;
var
a: array[1..100] of integer;
i, n, k, sum: integer;
avg: real;
begin
writeln('Nhap so phan tu trong mang: ');
readln(n);
writeln('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
writeln('Nhap so k: ');
readln(k);
sum := 0;
for i := 1 to n do
begin
if a[i] <= k then
sum := sum + a[i];
end;
if sum > 0 then
begin
avg := sum / n;
writeln('Trung binh cong cac phan tu co gia tri <= ', k, ' la: ', avg:0:2);
end
else
begin
writeln('Khong co phan tu nao co gia tri <= ', k);
end;
end.
Câu 3:
program DemSoNguyenTo;
var
a: array [1..100] of integer;
i, j, n, count: integer;
laSoNguyenTo: boolean;
begin
write('Nhap so phan tu cua mang: ');
readln(n);
write('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
count := 0;
writeln('Cac so nguyen to trong mang la: ');
for i := 1 to n do
begin
laSoNguyenTo := true;
for j := 2 to (a[i] div 2) do
begin
if (a[i] mod j = 0) then
begin
laSoNguyenTo := false;
break;
end;
end;
if laSoNguyenTo and (a[i] > 1) then
begin
writeln(a[i]);
count := count + 1;
end;
end;
writeln('Tong so cac so nguyen to la: ', count);
readln;
end.
uses crt;
var a:array[1..10]of integer;
i,n,dem:integer;
begin
clrscr;
for i:=1 to 10 do
begin
repeat
write('A[',i,']='); readln(a[i]);
until a[i]>0;
end;
writeln('Day so vua nhap la: ');
for i:=1 to 10 do
write(a[i]:4);
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln;
writeln('So luong so chan la: ',dem);
readln;
end.
Program Hoc24;
var a: array[1..32000] of integer;
d,i,n,x: integer;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('Nhap so thu ',i,': '); readln(a[i]);
end;
write('Nhap so can tim: '); readln(x);
d:=0;
for i:=1 to n do if a[i]=x then d:=d+1;
if d>0 then write('Co so can tim trong day ban dau') else write('Khong co so can tim trong day ban dau');
readln
end.
uses crt;
var a:array[1..100]of integer;
n,i,x,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap so can tim: '); readln(x);
kt:=0;
for i:=1 to n do
if a[i]=x then kt:=1;
if kt=0 then writeln(x,' khong co trong day')
else writeln(x,' co trong day');
readln;
end.
uses crt;
var n,i,k,dem:integer;
a: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;
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln('So phan tu chan trong day so la: ',dem);
write('Nhap so k='); readln(k);
kt:=0;
for i:=1 to n do
if a[i]=k then kt:=i;
if kt=0 then writeln('Khong co phan tu nao trong day bang ',k)
else writeln('Trong day co phan tu bang ',k);
readln;
end.
Lời giải :
program hotrotinhoc;
var a: array[1..100] of integer;
n,i,min : integer;
begin
write('n='); readln(n);
for i:= 1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
min:=a[1];
for i:= 2 to n do
if min>a[i] then min:=a[i];
write('Gia tri nho nhat trong day la :',min);
readln
end.