richie3366

tp7 ada

Nov 13th, 2012
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.73 KB | None | 0 0
  1. with entrees_sorties; use entrees_sorties;
  2.  
  3. procedure tp7_1 is
  4.   NB_ELTS : constant Integer := 100;
  5.  
  6.   subtype Intervalle is Integer range 1..NB_ELTS;
  7.   type TabEntiers is array(Intervalle) of Integer;
  8.  
  9.   monTabEntiers : TabEntiers;
  10.   entierCourant : Integer;
  11.   indice : Integer;
  12.   nbEntiers : Integer;
  13.  
  14.   produitTotal : Integer;
  15.   valMax, idMax : Integer;
  16.  
  17. begin
  18.  
  19.   indice := 1;
  20.   nbEntiers := 0;
  21.   entierCourant := 0;
  22.  
  23.   put("Entrez les [au plus 100] valeurs a stocker dans le tableau (terminez la saisie par -1)");
  24.   new_line;
  25.  
  26.   while(entierCourant /= -1 AND nbEntiers < NB_ELTS) loop
  27.     put("Valeur de l'element"&Integer'Image(indice)&" ?  ");
  28.     get(entierCourant);
  29.    
  30.     if(entierCourant /= -1) then
  31.       monTabEntiers(indice) := entierCourant;
  32.       indice := indice+1;
  33.       nbEntiers := nbEntiers+1;
  34.     end if;
  35.    
  36.   end loop;
  37.   if(nbEntiers > 0) then
  38.     put("Les"&Integer'Image(nbEntiers)&" valeurs contenues dans le tableau sont : ");
  39.    
  40.     produitTotal := 1;
  41.     valMax := 0;
  42.    
  43.     for i in 1..nbEntiers loop
  44.       put(monTabEntiers(i), 0);
  45.      
  46.       produitTotal := produitTotal * monTabEntiers(i);
  47.      
  48.       if(monTabEntiers(i) > valMax OR i = 1) then
  49.     valMax := monTabEntiers(i);
  50.     idMax := i;
  51.       end if;
  52.      
  53.       if(i < nbEntiers) then
  54.     put(", ");
  55.       else
  56.     put(".");
  57.       end if;
  58.      
  59.     end loop;
  60.    
  61.     new_line;
  62.     put("Le produit des elements est :"&Integer'Image(produitTotal));
  63.     new_line;
  64.     put("La valeur maximale stockee dans le tableau est :"&Integer'Image(valMax));
  65.     new_line;
  66.     put("Elle est situee a la position"&Integer'Image(idMax));
  67.    
  68.   else
  69.     put("Aucun entier n'a ete saisi.");
  70.   end if;
  71.  
  72.  
  73. end tp7_1;
Advertisement
Add Comment
Please, Sign In to add comment