LOVEGUN

Examen du baccalauréat - Session de Juin 2012

Jan 1st, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.99 KB | None | 0 0
  1. Program FactPrem;
  2. Uses Wincrt;
  3. Var
  4.   f1,f2: Text;
  5. Type
  6. tab=array [1..50] of integer;
  7. Procedure creation (Var f1,f2:Text);
  8. Begin
  9.   Assign (f1,'c:/bac/Nombres.txt');
  10.   Assign (f2,'c:/bac/Facteurs.txt');
  11. End;
  12.  
  13. Procedure facpremier (Var t:tab;n:Integer;Var j:Integer);
  14. Var
  15.   i: Integer;
  16.   ch: String;
  17.   x: String;
  18. Begin
  19.   i := 2;
  20.   j := 1;
  21.   Repeat
  22.     If n Mod i = 0 Then
  23.       Begin
  24.         t[j] := i;
  25.         j := j+1;
  26.         n := n Div i;
  27.       End
  28.     Else
  29.       i := i+1;
  30.   Until n=1;
  31.   j := j-1;
  32. End;
  33.  
  34. Procedure remplir (Var f1:Text);
  35. Var
  36.   n,x,i: Integer;
  37.   ch: String;
  38. Begin
  39.   Rewrite (f1);
  40.   Repeat
  41.     Writeln ('Saisir le nombre d''entiers: ');
  42.     Readln (n);
  43.   Until (2<n) And (n<100);
  44.   For i:=1 To n Do
  45.     Begin
  46.       Repeat
  47.         Writeln ('Saisir l''entier ',i,' : ');
  48.         Readln (x);
  49.         Str (x,ch);
  50.       Until (2<Length(ch)) And (Length(ch)<6);
  51.       Writeln (f1,ch);
  52.     End;
  53.   Close (f1);
  54. End;
  55. Function comptage (n:Integer;t:tab;ch:Integer): Integer;
  56. Var
  57.   x: Integer;
  58.   i: Integer;
  59. Begin
  60.   x := 0;
  61.   For i:=1 To ch Do
  62.     If n=t[i] Then
  63.       x := x+1;
  64.   comptage := x;
  65. End;
  66. Procedure traitement (Var f1,f2:Text);
  67. Var
  68.   t: tab;
  69.   x: Integer;
  70.     j,i:integer;
  71.     aux1,aux2,aux,final:string;
  72.    
  73. Begin
  74.   Reset (f1);
  75.   Rewrite (f2);
  76.     While Not (Eof(f1)) Do
  77.     Begin
  78.       Readln (f1,x);
  79.                 facpremier (t,x,j);
  80.                 final:='';
  81.       For i:=1 To j Do
  82.         Begin
  83.           Str (comptage (t[i],t,j),aux1);
  84.           Str (t[i],aux2);
  85.           aux := aux1+aux2;
  86.           final := final+aux;
  87.           If comptage (t[i],t,j)>1 Then
  88.             i := i+comptage (t[i],t,j)-1;
  89.         End;
  90.       Writeln (f2,x,' : ',final);
  91.     End;
  92.   Close (f1);
  93.   Close (f2);
  94. End;
  95. Procedure affiche (Var f2:Text);
  96. Var ch:string;
  97. Begin
  98.     reset (f2);
  99.     while not (eof(f2)) Do
  100.         Begin
  101.             readln (f2,ch);
  102.             writeln (ch);
  103.         End;
  104.     close (f2);
  105. End;
  106. Begin
  107.   creation (f1,f2);
  108.   remplir (f1);
  109.   traitement (f1,f2);
  110.   affiche (f2);
  111. End.
  112.  
Advertisement
Add Comment
Please, Sign In to add comment