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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| Program Rigolo ;
Uses WinCrt , Crt ;
Var f : text ; n,m : integer ;
Procedure saisie ( var n , m : integer );
Begin
Repeat
Write ('M = '); Readln (m) ;
Until m > 100 ;
Repeat
Write ('N = '); Readln (n) ;
Until (n > m) and (n < 1000)
End;
Function somchif ( x : integer ) : integer ;
Var ch : string ; nb , i : integer ;
Begin
Str (x,ch) ;
nb := 0 ;
For i := 1 to length(ch) Do
nb := nb + (Ord ( ch[i] ) - 48) ;
somchif := nb ;
end;
Function fp ( x : integer ) : string ;
Var i : integer ; ch , chi : string ;
Begin
i := 2 ;
ch := '' ;
Repeat
If (x Mod i ) = 0 then
Begin
str (i,chi) ;
ch := ch + chi + '*' ;
x := x Div i ;
End;
i := i + 1 ;
Until n = 1 ;
fp := copy (ch,1,length(ch)-1) ;
End;
Procedure remplir ( var f : text ; n , m : integer ) ;
Var ch : string ; i , j , nb , sfp : integer ;
Begin
Rewrite (f) ;
For i := m to n Do
Begin
nb := i ;
sfp := 0 ;
j := 2 ;
Repeat
If (( nb Mod j ) = 0) then
Begin
sfp := sfp + somchif (j) ;
nb := n Div j ;
end;
j := j + 1 ;
until nb = 1 ;
If (somchif(i) = sfp) then
Begin
Str (i,ch) ;
Writeln (f,ch+' = '+fp(i));
end;
end;
End;
Procedure afficher ( var f : text ) ;
Var ch : string ; ok : boolean ;
Begin
Reset (f) ;
ok := false ;
While not ( eof (f)) Do
Begin
Readln (f,ch) ;
Writeln (ch) ;
ok := true ;
End;
If not (ok) then Writeln ('Aucun nombre rigolo');
End;
Begin
Assign (f,'S:\fich\Resultats.Txt');
saisie (n,m) ;
remplir (f,n,m) ;
afficher (f) ;
Readln;
End. |
Partager