1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| PROGRAM BAC2014 ;
USES WINCRT ;
VAR i,n,m:integer;
procedure saisir(var n,m:integer);
begin
repeat
writeln('ecrire l''entier n et m');
readln(n,m);
until ((n>=100)and(m>n));
end;
function chercher(m,n:integer):boolean;
var i,s,a,x,b,nb,e:integer;
ch:string;
test:boolean;
begin
for i:=n to m do
begin
s:=0;
str(i,ch);
for a:=1 to length(ch) do
begin
val(ch[i],x,e);
s:=x+s;
end;
nb:=0;
for b:=1 to i-1 do
begin
if (((i-1) mod b)=0) then
nb:=nb+1;
end;
if((i mod s=0) and(nb=2)) then
test:=true
else test:=false
end;
chercher:=test;
end;
begin
saisir(n,m);
for i:=n to m do
begin
if chercher(m,n)=true then
writeln(i,'car',i,' est hashard et son predecesseur ',i-1,'est un nombre premier') ;
end;
end. |
Partager