var N,n1,i,s:integer;
{ham tinh so nguyen to}
function snt(x:integer):boolean;
var i:integer;
begin
snt:=x>1;
for i:= 2 to x-1 do if x mod i =0 then snt:=false;
end;
{ham tinh tong cac chu so cua 1 so}
function tong(n:integer):integer;
var s:integer;
begin
s:=0;
while n>0 do
begin
s:=s+ n mod 10;
n:=n div 10;
end;
end;
begin
clrscr;
repeat
write('Nhap n:'); read(n);
until (n>1) and(n<1000);
writeln('Tong cac chu so cua n:',tong(n));
{xet xem n co phai la so song to hay khong}
if snt(n) and snt(tong(n)) then write('N la so song to')
else write('N khong phai so song to');
{in ra cac so song to tu 1 den 100}
for i:=1 to 100 do if snt(i) and snt(tong(i)) then write(i, ' ');
readkey;
end.
{ham tinh so nguyen to}
function snt(x:integer):boolean;
var i:integer;
begin
snt:=x>1;
for i:= 2 to x-1 do if x mod i =0 then snt:=false;
end;
{ham tinh tong cac chu so cua 1 so}
function tong(n:integer):integer;
var s:integer;
begin
s:=0;
while n>0 do
begin
s:=s+ n mod 10;
n:=n div 10;
end;
end;
begin
clrscr;
repeat
write('Nhap n:'); read(n);
until (n>1) and(n<1000);
writeln('Tong cac chu so cua n:',tong(n));
{xet xem n co phai la so song to hay khong}
if snt(n) and snt(tong(n)) then write('N la so song to')
else write('N khong phai so song to');
{in ra cac so song to tu 1 den 100}
for i:=1 to 100 do if snt(i) and snt(tong(i)) then write(i, ' ');
readkey;
end.
Rất hay, cám ơn ad
Trả lờiXóaCAESAR