bài của bạn thiếu câu lệnh in ra số các số nguyên tố nha
mình bổ sung thêm vào rùi đó
Uses CRT;
Var a: Array [1..100] of Integer;
i,n,p,s: Integer;
Function ktnt (n: Integer): Boolean;
Var i,d,p: Integer;
Begin
d:=0;
If n<2 then
ktnt:=false
Else
Begin
p:=0;
For i:=1 to n do
If n mod i=0 then
d:=d+1;
End;
If d=2 then
ktnt:=true
Else
ktnt:=false;
End;
Function kthh (n:Integer): Boolean;
Var i,s: Integer;
Begin
s:=0;
For i:=1 to n div 2 do
If n mod i=0 then
s:=s+i;
If s=n then
kthh:=true
Else
kthh:=false;
End;
Begin
ClrScr;
Write ( 'Nhap so nguyen n: ');
Readln (n);
For i:=1 to n do
Begin
Write ( 'Nhap phan tu thu ',i,': ');
Readln (a[i]);
End;
Write ( 'Cac so nguyen to co trong day tren la: ' );
For i:=1 to n do
Begin
If ktnt (a[i])=true then
Begin
Write (a[i],' ');
End;
End;
For i:=1 to n do
If ktnt (a[i])=true then
p:=p+1;
Writeln;
writeln('Co ',p,' so nguyen to');
Write ( 'Cac so hoan hao co trong day tren la: ');
For i:=1 to n do
If kthh (a[i])=true then
Write(a[i],' ');
Readln;
End.
Uses CRT;
Var a: Array [1..100] of Integer;
i,n,p,s: Integer;
Function ktnt (n: Integer): Boolean;
Var i,d,p: Integer;
Begin
d:=0;
If n<2 then
ktnt:=false
Else
Begin
p:=0;
For i:=1 to n do
If n mod i=0 then
d:=d+1;
End;
If d=2 then
ktnt:=true
Else
ktnt:=false;
End;
Function kthh (n:Integer): Boolean;
Var i,s: Integer;
Begin
s:=0;
For i:=1 to n div 2 do
If n mod i=0 then
s:=s+i;
If s=n then
kthh:=true
Else
kthh:=false;
End;
Begin
ClrScr;
Write ( 'Nhap so nguyen n: ');
Readln (n);
For i:=1 to n do
Begin
Write ( 'Nhap phan tu thu ',i,': ');
Readln (a[i]);
End;
Write ( 'Cac so nguyen to co trong day tren la: ' );
For i:=1 to n do
Begin
If ktnt (a[i])=true then
Begin
Write (a[i],' ');
End;
End;
For i:=1 to n do
If ktnt (a[i])=true then
p:=p+1;
Writeln;
writeln('Co ',p,' so nguyen to');
Write ( 'Cac so hoan hao co trong day tren la: ');
For i:=1 to n do
If kthh (a[i])=true then
Write(a[i],' ');
Readln;
End.