program an_danh;
uses crt;
var n,i,tong,nd,x,nx:integer;
a: array [1..10000] of integer;
begin
clrscr;
repeat
write('Nhap so phan tu: ');readln(n);
if n > 10000 then
begin
write('Nhap so <= 10000');
delay(2000);
clrscr;
end;
until n <= 10000;
for i:= 1 to n do
begin
repeat
write('Phan tu thu ',i,': ');
readln(a[i]);
if a[i] > 107 then
begin
write('Nhap so <= 107');
delay(2000);
clrscr;
end;
until a[i] <= 107;
end;
write('Nhap phan tu x: ');readln(x);
nd:= 0; tong:= 0; nx:= 0;
for i:= 1 to n do
begin
if a[i] >= 0 then
begin
nd:= nd + 1;
tong:= tong + a[i];
end;
if a[i] = x then nx:= nx + 1;
end;
writeln('So cac so hang duong: ',nd);
writeln('Tong cac so hang duong: ',tong);
write('So cac phan tu = x la: ',nx);
readln
end.
uses crt;
var a:array[1..10000]of longint;
i,n,dem,t,x,dx:longint;
begin
clrscr;
write('n='); readln(n);
if (n>0) and (n<=10000) then
begin
for i:=1 to n do
begin
repeat
write('a[',i,']='); readln(a[i]);
if a[i]>107 then writeln('vui long nhap lai');
until a[i]<=107;
end;
{-----------------------cau-1-------------------------}
dem:=0;
t:=0;
for i:=1 to n do
if a[i]>0 then
begin
dem:=dem+1;
t:=t+a[i];
end;
writeln('so luong cac so hang duong la: ',dem);
writeln('tong cac so hang duong la: ',t);
{---------------------cau-2----------------------------}
write('x='); readln(x);
dx:=0;
for i:=1 to n do
if a[i]=x then inc(dx);
writeln('so luong cac phan tu bang ',x,' la: ',dx);
end
else writeln('vui long nhap lai n');
readln;
end.
Source: https://ideone.com/2STT8c (C++ 14)
Chúc bạn học tốt nha