Forum ada95000 Dernière connexion : 18/06/2025 à 09:40
Fin de session : 18/06/2025 à 09:50

Vous n'êtes pas connecté [Connexion - Inscription]
Go Bottom
Version imprimable | Envoyer à un ami | S'abonner | Ajouter aux Favoris Nouveau SujetNouveau sondageRépondre
Auteur: Sujet: Exo 7: Multiplication Russe   ( Réponses: 1 | Vues: 643 )
ftbass
Administrator
StaffStaffStaffStaffStaffStaffStaffStaffStaff
 
images/avatars/WC3HumanOp1.gif
 
Messages: 72
Inscrit(e) le: 27/02/2004
Déconnecté(e)
Publié le 09/03/2004 à 20:25 Reply With Quote
Exo 7: Multiplication Russe

code:
with text_io; use text_io;

procedure mult_russ is

  package entier_es is new text_io.integer_io(integer);
  use entier_es;
  a, b : integer;
  min, max, p : integer;

begin
  put("donner la valeur de a : ");
  get(a);
  put("donner la valeur de b : ");
  get(b);
  if (a>b) then
     max := a;
     min := b;
  else
     max := b;
     min := a;
  end if;
  p := 0;
  while (min /= 1) loop
     if ((min mod 2) = 1) then p := p + max;
     end if;
     min := min / 2;
     max := 2 * max;
  end loop;
  p := p + max;
  new_line;
  put("a * b = "); put(p);
end mult_russ;


[Edité le 16/03/2004 à 09:56 par ftbass]
Go Top #8 Go Bottom
View ftbass's ProfileE-Mail ftbassVisit ftbass's HomepageView All Posts by ftbassU2U Member
Yossep
VIP
MembreMembreMembreMembre
 
 
Messages: 10
Inscrit(e) le: 31/05/2020
Déconnecté(e)
Publié le 04/06/2020 à 22:36 Reply With Quote
RE : Exo 7: Multiplication Russe

Histoire de ressusciter le Forum :-?

Code:
Multiplications.ads
quote: With Ada.Text_IO, Ada.Integer_Text_IO;

package Multiplications is
 
  package ES_Mes_Entiers is new Ada.Text_IO.Integer_IO(Integer);
  Use ES_Mes_Entiers;
 
  procedure MultiRusse;
 
 

end Multiplications;


Fichier
Multiplications.adb

quote: With Ada.Text_IO;
Use Ada.Text_IO;

package body Multiplications is

  procedure MultiRusse is
     A, B : Integer;
     Min, Max, P : Integer;
     
  begin
     Put_line("Donnez la valeur de A:");
     Put(">");Get(A);Skip_Line;
     Put_line("Donnez la valeur de B:");
     Put(">");Get(B);Skip_line;
     
     if(A > B) then
        Max := A;
        Min := B;
     else
        Max := B;
        Min := A;
     end if;
     
     P := 0;
     
     while(Min /= 1) loop
       
        if( (Min mod 2) = 1) then P := P + Max;
        end if;
       
        Min := Min / 2;
        Max := 2 * Max;
     end loop;
     P := P + Max;
     New_Line;
     Put("A * B = ");Put(P, 2);
     
  end MultiRusse;
 

end Multiplications;


Programme principal
main.adb

quote: With Multiplications;
Use Multiplications;

procedure Main is

begin
  MultiRusse;
end Main;
Go Top #106 Go Bottom
View Yossep's ProfileE-Mail YossepView All Posts by YossepU2U Member
Nouveau SujetNouveau sondageRépondre

Go Top
10.3.122.74 09:40 - 18 Juin 2025 10.3.122.74
[ 0.0780890 secondes | Effacer le cookie | 18 requêtes ]
Oxygen v1.0.11 © 2002  |  Oxygen WebSite © 2002