Code:
program baitap;
uses crt;
{-- Hàm KT nguyên tố --}
function nt(n : integer) : boolean;
var i:integer;
begin
nt:=false;
if n<2 then exit;
for i:=2 to trunc(sqrt(n)) do if n mod i=0 then exit;
nt:=true;
end;
{-- Hàm KT số chính phương --}
function cp(n:integer) : boolean;
var i : integer;
begin
cp:=false;
for i:=1 to trunc(sqrt(n)) do
if i*i = n then cp:=true; exit;
end;
{-- Chương trình chính --}
var i,j,m,n,k,a,b,c : integer;
a : array[1..200,1..200] of integer;
begin
clrscr;
write('Nhap m va n : ');
readln(m,n);
write('Nhap k : ');
readln(k);
clrscr;
for i:=1 to m do
for j:=1 to n do
begin
write('A[',i,',',j,'] = ');
readln(a[i,j]);
if a[i,j]=k then inc(a);
if nt(a[i,j])=true then inc(b);
if cp(a[i,j])=true then inc(c);
end;
write('Co ',a,' so giong k');
write('Co ',b,' so nguyen to');
write('Co ',c,' so chinh phuong');
readln;
end.
Bookmarks