Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2569 connectés 

  FORUM HardWare.fr
  Programmation
  Ada

  fonction split sur un entier

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

fonction split sur un entier

n°2108839
kirua94
Posté le 31-10-2011 à 07:29:05  profilanswer
 

Bonjour,  
Sur un td que nous réaliser en cour , je bloque sur cette question depuis deux jours.
Dans un programme , l 'utilisateur doit taper un entier et le programme affiche chaque chiffre séparé par un point.
par exemple, si l’entier 456 est passé en paramètre, cela affichera "4.5.6.".
 
merci d'avance

mood
Publicité
Posté le 31-10-2011 à 07:29:05  profilanswer
 

n°2109100
Profil sup​primé
Posté le 01-11-2011 à 18:25:53  answer
 

L'attribut 'image est ton ami
 
 
for i in 2..integer'image(un_int)'length loop
 put(integer'image(un_int)(i));
 exit when integer'image(un_int)'length = i;
 put('.');
end loop;


Message édité par Profil supprimé le 01-11-2011 à 18:26:35
n°2109108
Profil sup​primé
Posté le 01-11-2011 à 18:41:26  answer
 

void:/home/root/dot_int# cat main.adb


Code :
  1. with Ada.Command_Line, Ada.Text_Io;
  2. use Ada;
  3. procedure Main is
  4.   Un_Int : Integer := 0;
  5. begin
  6.   if Command_Line.Argument_Count /= 1 then
  7.      Text_Io.Put_Line("Erreur d'arguments" );
  8.   else
  9.      begin
  10.         Un_Int := Integer'Value(Command_Line.Argument(1));
  11.         for I in 2..Integer'Image(Un_Int)'Length loop
  12.            Text_Io.Put(Integer'Image(Un_Int)(I));
  13.            exit when Integer'Image(Un_Int)'Length = I;
  14.            Text_Io.Put('.');
  15.         end loop;
  16.      exception
  17.         when Constraint_Error =>
  18.            Text_Io.Put_Line("Argument invalide." );
  19.      end;
  20.   end if;
  21. end Main;


void:/home/root/dot_int# ./main 123456789
1.2.3.4.5.6.7.8.9
void:/home/root/dot_int#
 


Voila de rien, bienvenue !


Message édité par Profil supprimé le 01-11-2011 à 18:41:41

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Ada

  fonction split sur un entier

 

Sujets relatifs
fonction mail() phpIntercepter une fonction en lua ?
Jeu du morpion (fonction détection)Appel d'une fonction javascript ) partir d'un href
Récupérer valeur d'un select en fonction de son idProblème de fonction avec IE
Fonction non définieutilisation de la propriete innerHTML dans une fonction JS
fonction exec ou shell_exec lancer depuis un navigateurrecherche fonction javasript
Plus de sujets relatifs à : fonction split sur un entier


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR