begin process at 2010 02 09 23:13:34
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Chaîne de caractères

 > LIBELLER UN NOMBRE ENTIER EN CHAINE DE CARACTÈRE

LIBELLER UN NOMBRE ENTIER EN CHAINE DE CARACTÈRE


 Information sur la source

Note :
5,5 / 10 - par 2 personnes
5,50 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Chaîne de caractères Niveau :Initié Date de création :09/12/2003 Vu :2 751

Auteur : mtougui

Ecrire un message privé
Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

 Description

Transformer un nombre entier en chaine de caractère
Je n'est pas utiliser de fonctions dans ce code
Mais vous pouvez le changer et l'améliorer

Source

  • #include<stdio.h>
  • #include<conio.h>
  • #include<string.h>
  • void main()
  • {unsigned long nombre,dizaine,dix_reste,centaine,centaine_reste,mille,mille_reste,million,million_reste,milliard,milliard_reste;
  • struct libeller1{char zero_seize[10];}libeller_zero_seize[20];
  • struct libeller2{char dizaines[20];}libeller_dizaines[20];
  • struct libeller3{char puissances[10];}libeller_puissances[20];
  • //affectation des libellers
  • //libeller de 0 . 16
  • strcpy(libeller_zero_seize[0].zero_seize,"z,ro");
  • strcpy(libeller_zero_seize[1].zero_seize,"un");
  • strcpy(libeller_zero_seize[2].zero_seize,"deux");
  • strcpy(libeller_zero_seize[3].zero_seize,"trois");
  • strcpy(libeller_zero_seize[4].zero_seize,"quatre");
  • strcpy(libeller_zero_seize[5].zero_seize,"cinq");
  • strcpy(libeller_zero_seize[6].zero_seize,"six");
  • strcpy(libeller_zero_seize[7].zero_seize,"sept");
  • strcpy(libeller_zero_seize[8].zero_seize,"huit");
  • strcpy(libeller_zero_seize[9].zero_seize,"neuf");
  • strcpy(libeller_zero_seize[10].zero_seize,"dix");
  • strcpy(libeller_zero_seize[11].zero_seize,"onze");
  • strcpy(libeller_zero_seize[12].zero_seize,"douze");
  • strcpy(libeller_zero_seize[13].zero_seize,"treize");
  • strcpy(libeller_zero_seize[14].zero_seize,"quatorze");
  • strcpy(libeller_zero_seize[15].zero_seize,"quinze");
  • strcpy(libeller_zero_seize[16].zero_seize,"seize");
  • //libeller les dizaines
  • strcpy(libeller_dizaines[1].dizaines,"dix");
  • strcpy(libeller_dizaines[2].dizaines,"vingt");
  • strcpy(libeller_dizaines[3].dizaines,"trente");
  • strcpy(libeller_dizaines[4].dizaines,"quarante");
  • strcpy(libeller_dizaines[5].dizaines,"cinquante");
  • strcpy(libeller_dizaines[6].dizaines,"soixante");
  • strcpy(libeller_dizaines[7].dizaines,"soixante-dix");
  • strcpy(libeller_dizaines[8].dizaines,"quatre-vingt");
  • strcpy(libeller_dizaines[9].dizaines,"quatre-vingt-dix");
  • //libeller les puissances
  • strcpy(libeller_puissances[0].puissances,"cent");
  • strcpy(libeller_puissances[1].puissances,"mille");
  • strcpy(libeller_puissances[2].puissances,"million");
  • strcpy(libeller_puissances[3].puissances,"milliard");
  • //menu principales
  • mille=0;mille_reste=0;
  • million=0;million_reste=0;
  • milliard=0;milliard_reste=0;
  • clrscr();
  • printf("Donner l'entier . libeller : ");
  • scanf("%lu",&nombre);
  • retour:
  • if((nombre>=0)&&(nombre<=16))
  • printf("%s",libeller_zero_seize[nombre].zero_seize);
  • if((nombre>=17)&&(nombre<=99))
  • {
  • dizaine=nombre/10;
  • dix_reste=nombre%10;
  • if((dix_reste==0)&&(nombre!=80)) printf("%s",libeller_dizaines[dizaine].dizaines);
  • else
  • if (nombre==80) printf("%ss",libeller_dizaines[dizaine].dizaines);
  • else
  • if(((nombre>=71)&&(nombre<=76))||((nombre>=91)&&(nombre<=96)))
  • {
  • printf("%s",libeller_dizaines[dizaine-1].dizaines);
  • printf("-%s",libeller_zero_seize[dix_reste+10].zero_seize);
  • }
  • else
  • if (dix_reste!=1)
  • {
  • printf("%s",libeller_dizaines[dizaine].dizaines);
  • printf("-%s",libeller_zero_seize[dix_reste].zero_seize);
  • }
  • else
  • {
  • printf("%s",libeller_dizaines[dizaine].dizaines);
  • printf(" et %s",libeller_zero_seize[dix_reste].zero_seize);
  • }
  • }
  • if((nombre>=100)&&(nombre<=999))
  • {
  • centaine=nombre/100;
  • centaine_reste=nombre%100;
  • if(centaine!=1)
  • {
  • printf("%s",libeller_zero_seize[centaine].zero_seize);
  • if (centaine_reste)
  • printf(" %s ",libeller_puissances[0].puissances);
  • else
  • printf(" %ss",libeller_puissances[0].puissances);
  • }
  • else printf("%s ",libeller_puissances[0].puissances);
  • if(centaine_reste)
  • {
  • nombre=centaine_reste;
  • goto retour;
  • }
  • }
  • if((nombre>=1000)&&(nombre<=999999))
  • {
  • mille=nombre/1000;
  • mille_reste=nombre%1000;
  • if(mille==1)
  • printf("%s ",libeller_puissances[1].puissances);
  • else
  • {
  • nombre=mille;
  • goto retour;
  • }
  • }
  • if(mille)
  • {
  • if(mille!=1) printf(" %s ",libeller_puissances[1].puissances);
  • mille=0;
  • if(mille_reste!=0)
  • {
  • nombre=mille_reste;
  • goto retour;
  • }
  • }
  • if((nombre>=1000000)&&(nombre<=999999999))
  • {
  • million=nombre/1000000;
  • million_reste=nombre%1000000;
  • nombre=million;
  • goto retour;
  • }
  • if(million)
  • {
  • if(million==1) printf(" %s ",libeller_puissances[2].puissances);
  • else printf(" %ss ",libeller_puissances[2].puissances);
  • million=0;
  • if(million_reste!=0)
  • {
  • nombre=million_reste;
  • goto retour;
  • }
  • }
  • if((nombre>=1000000000)&&(nombre<=4294967295))
  • {
  • milliard=nombre/1000000000;
  • milliard_reste=nombre%1000000000;
  • nombre=milliard;
  • goto retour;
  • }
  • if(milliard)
  • {
  • if(milliard==1) printf(" %s ",libeller_puissances[3].puissances);
  • else printf(" %ss ",libeller_puissances[3].puissances);
  • milliard=0;
  • if(milliard_reste!=0)
  • {
  • nombre=milliard_reste;
  • goto retour;
  • }
  • }
  • getch();
  • }
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{unsigned long nombre,dizaine,dix_reste,centaine,centaine_reste,mille,mille_reste,million,million_reste,milliard,milliard_reste;
struct  libeller1{char zero_seize[10];}libeller_zero_seize[20];
struct  libeller2{char dizaines[20];}libeller_dizaines[20];
struct  libeller3{char puissances[10];}libeller_puissances[20];
//affectation des libellers
//libeller de 0 . 16
strcpy(libeller_zero_seize[0].zero_seize,"z,ro");
strcpy(libeller_zero_seize[1].zero_seize,"un");
strcpy(libeller_zero_seize[2].zero_seize,"deux");
strcpy(libeller_zero_seize[3].zero_seize,"trois");
strcpy(libeller_zero_seize[4].zero_seize,"quatre");
strcpy(libeller_zero_seize[5].zero_seize,"cinq");
strcpy(libeller_zero_seize[6].zero_seize,"six");
strcpy(libeller_zero_seize[7].zero_seize,"sept");
strcpy(libeller_zero_seize[8].zero_seize,"huit");
strcpy(libeller_zero_seize[9].zero_seize,"neuf");
strcpy(libeller_zero_seize[10].zero_seize,"dix");
strcpy(libeller_zero_seize[11].zero_seize,"onze");
strcpy(libeller_zero_seize[12].zero_seize,"douze");
strcpy(libeller_zero_seize[13].zero_seize,"treize");
strcpy(libeller_zero_seize[14].zero_seize,"quatorze");
strcpy(libeller_zero_seize[15].zero_seize,"quinze");
strcpy(libeller_zero_seize[16].zero_seize,"seize");
//libeller les dizaines
strcpy(libeller_dizaines[1].dizaines,"dix");
strcpy(libeller_dizaines[2].dizaines,"vingt");
strcpy(libeller_dizaines[3].dizaines,"trente");
strcpy(libeller_dizaines[4].dizaines,"quarante");
strcpy(libeller_dizaines[5].dizaines,"cinquante");
strcpy(libeller_dizaines[6].dizaines,"soixante");
strcpy(libeller_dizaines[7].dizaines,"soixante-dix");
strcpy(libeller_dizaines[8].dizaines,"quatre-vingt");
strcpy(libeller_dizaines[9].dizaines,"quatre-vingt-dix");
//libeller les puissances
strcpy(libeller_puissances[0].puissances,"cent");
strcpy(libeller_puissances[1].puissances,"mille");
strcpy(libeller_puissances[2].puissances,"million");
strcpy(libeller_puissances[3].puissances,"milliard");
//menu principales
mille=0;mille_reste=0;
million=0;million_reste=0;
milliard=0;milliard_reste=0;
clrscr();
printf("Donner l'entier . libeller : ");
scanf("%lu",&nombre);
retour:
if((nombre>=0)&&(nombre<=16))
printf("%s",libeller_zero_seize[nombre].zero_seize);
if((nombre>=17)&&(nombre<=99))
{
dizaine=nombre/10;
dix_reste=nombre%10;
if((dix_reste==0)&&(nombre!=80)) printf("%s",libeller_dizaines[dizaine].dizaines);
else
if (nombre==80) printf("%ss",libeller_dizaines[dizaine].dizaines);
else
if(((nombre>=71)&&(nombre<=76))||((nombre>=91)&&(nombre<=96)))
   {
   printf("%s",libeller_dizaines[dizaine-1].dizaines);
   printf("-%s",libeller_zero_seize[dix_reste+10].zero_seize);
   }
else
if (dix_reste!=1)
   {
   printf("%s",libeller_dizaines[dizaine].dizaines);
   printf("-%s",libeller_zero_seize[dix_reste].zero_seize);
   }
else
   {
   printf("%s",libeller_dizaines[dizaine].dizaines);
   printf(" et %s",libeller_zero_seize[dix_reste].zero_seize);
   }
}
if((nombre>=100)&&(nombre<=999))
{
centaine=nombre/100;
centaine_reste=nombre%100;
if(centaine!=1)
  {
  printf("%s",libeller_zero_seize[centaine].zero_seize);
  if (centaine_reste)
  printf(" %s ",libeller_puissances[0].puissances);
  else
  printf(" %ss",libeller_puissances[0].puissances);
  }
else printf("%s ",libeller_puissances[0].puissances);
if(centaine_reste)
 {
 nombre=centaine_reste;
 goto retour;
 }

}
if((nombre>=1000)&&(nombre<=999999))
{
mille=nombre/1000;
mille_reste=nombre%1000;
if(mille==1)
printf("%s ",libeller_puissances[1].puissances);
else
 {
 nombre=mille;
 goto retour;
 }
}
if(mille)
{
if(mille!=1) printf(" %s ",libeller_puissances[1].puissances);
mille=0;
if(mille_reste!=0)
 {
 nombre=mille_reste;
 goto retour;
 }
}
if((nombre>=1000000)&&(nombre<=999999999))
{
million=nombre/1000000;
million_reste=nombre%1000000;
nombre=million;
goto retour;
}
if(million)
{
if(million==1) printf(" %s ",libeller_puissances[2].puissances);
else printf(" %ss ",libeller_puissances[2].puissances);
million=0;
if(million_reste!=0)
 {
 nombre=million_reste;
 goto retour;
 }
}
if((nombre>=1000000000)&&(nombre<=4294967295))
{
milliard=nombre/1000000000;
milliard_reste=nombre%1000000000;
nombre=milliard;
goto retour;
}
if(milliard)
{
if(milliard==1) printf(" %s ",libeller_puissances[3].puissances);
else printf(" %ss ",libeller_puissances[3].puissances);
milliard=0;
if(milliard_reste!=0)
 {
 nombre=milliard_reste;
 goto retour;
 }
}
getch();
}



 Sources du même auteur

LA CLASSE MINT EST UN ENTIER N'AYANT PAS DE MAXIMUM
MASTERMIND
Source avec Zip BISSECTION,SECANTE,NEWTON
L'ALGORITHME DES 8 REINES

 Sources de la même categorie

Source avec Zip RECHERCHE D'ANNAGRAMMES par Torin
GESTION DE CHAINE DE CARACTÉRE EN C++ AVEC NSTRING par xmustapha
Source avec Zip COMMENTER CODE C <=> ASM (WIN64) par BruNews
Source avec Zip GSTRING - GESTION DES CHAINES DE CARACTÈRES par Neokript
Source avec Zip ANALYSEUR SYNTAXIQUEV(0.1) par kohan95

Commentaires et avis

Commentaire de BruNews le 09/12/2003 23:22:59 administrateur CS

strcpy est une macro dont le code est mis inline par tout compilo correct.

Commentaire de hussein le 21/10/2004 21:23:45

voir itoa!!!

Commentaire de Big cent le 15/04/2008 15:44:21

J'utilise le dev cpp mais dès que je compile cela ne marche pas.

Commentaire de Big cent le 08/01/2009 11:43:42

Je compile sous Dev Cpp mais ça ne marche il m'affiche:
139 D:\Langage C\Conversion entier en chaine de caractere.c [Warning] this decimal constant is unsigned only in ISO C90

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,624 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales