Advertisement
LOVEGUN

Bac 2011 (Cours particulier)

May 15th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.71 KB | None | 0 0
  1. Program bac2011;
  2. Uses Wincrt;
  3. Var
  4.     m,n:integer;
  5.     f:text;
  6. Procedure saisie (Var m,n:Integer);
  7. Begin
  8.   Repeat
  9.     Write ('Saisir M: ');
  10.     Readln (m);
  11.     Write ('Saisir N: ');
  12.     Readln (n);
  13.   Until (100<m) And (m<n) And (n<1000);
  14. End;
  15.  
  16. Function fact (n:Integer): String;
  17. Var
  18. ch,ch1:string;
  19. r:integer;
  20. Begin
  21.   r := 2;
  22.   ch := '';
  23.   Repeat
  24.     If n Mod r =0 Then
  25.       Begin
  26.         Str (r,ch1);
  27.         ch := ch+ch1+'*';
  28.         n := n Div r;
  29.       End
  30.     Else
  31.       r := r+1;
  32.   Until (n=1);
  33.   fact := ch;
  34. End;
  35. function somme (ch:string):integer;
  36. Var
  37. s,x,e,i:integer;
  38. Begin
  39.     s:=0;
  40.     for i:=1 to Length(ch) Do
  41.         Begin
  42.             val (ch[i],x,e);
  43.             s:=s+x;
  44.         end;
  45.     somme:=s;
  46. end;
  47. Procedure traitement (Var f:Text;m,n:Integer);
  48. Var
  49.   x,e,i,s: Integer;
  50.     ch,ch1:string;
  51. Begin
  52.   Rewrite (f);
  53.   For i:=m To n Do
  54.     Begin
  55.       ch := fact(i);
  56.       s := 0;
  57.       Repeat
  58.         If Length(Copy(ch,1,Pos('*',ch)-1))>1 Then
  59.           Begin
  60.             s := s+somme(Copy(ch,1,Pos('*',ch)-1));
  61.             Delete (ch,1,Pos('*',ch));
  62.           End
  63.         Else
  64.           Begin
  65.             Val (Copy(ch,1,Pos('*',ch)-1),x,e);
  66.             s := s+x;
  67.             Delete (ch,1,Pos('*',ch));
  68.           End;
  69.       Until (ch='');
  70.       Str(i,ch1);
  71.       If somme(ch1)=s Then
  72.         Writeln (f,i,'=',Copy(fact(i),1,Length(fact(i))-1));
  73.     End;
  74.   Close (f);
  75. End;
  76. procedure affiche (var f:text);
  77. Var
  78. ch:string;
  79. Begin
  80.     reset (f);
  81.     if (eof(f)) Then
  82.         writeln ('Il n''ya aucun nombre rigolo')
  83.     else
  84.         while not (eof(f)) Do
  85.             Begin
  86.                 readln (f,ch);
  87.                 writeln (ch);
  88.             end;
  89.     close (f);
  90. end;
  91. Begin
  92.     saisie (m,n);
  93.     assign (f,'c:\bac\resultat.txt');
  94.     traitement (f,m,n);
  95.     affiche (f);
  96. End.
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement