begin process at 2012 02 10 11:09:33
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Chaîne de caractères

 > EXAMPLE CLASSIQUE: CONVERTION ENTIER EN CHIFFRE ROMAINE ET <<-- (LANG- C )

EXAMPLE CLASSIQUE: CONVERTION ENTIER EN CHIFFRE ROMAINE ET <<-- (LANG- C )


 Information sur la source

Note :
6 / 10 - par 1 personne
6,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Chaîne de caractères Niveau :Initié Date de création :10/07/2002 Date de mise à jour :10/07/2002 20:47:56 Vu :4 561

Auteur : natpoitiers

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

 Description

ARAB-->ROMAN et ROMAN -->ARAB
Peut etre vous avez aussi les problemes avec cette exercise a l'ecole? Par example, dans notre groupe personne n'a pas trouve une solution. C'est facile!

Source

  • #include <stdio.h>
  • #include <string.h>
  • #include <stdlib.h>
  • #include <ctype.h>
  • void roman()
  • {
  • int ones, tens, hundreds, thousands, temp, input, x;
  • char rO[100] = "";
  • char rTens[100] = "";
  • char rHundreds[100] = "";
  • char rThousands[100] = "";
  • char *rTemp;
  • for(;;)
  • {
  • printf( "Votre nombre: (si 0 - revenir dans menu) ");
  • scanf("%d",& input);
  • if(input==0) break;
  • printf( "\n\nArabic %d: ",input);
  • thousands = input/1000;
  • hundreds = (input-(thousands*1000))/100;
  • tens= (input-(thousands*1000 + hundreds*100))/10;
  • ones= (input-(thousands*1000 + hundreds*100 + tens*10));
  • temp = 0;
  • while(temp!=thousands)
  • {
  • rTemp = "M";
  • strcat(rThousands, rTemp);
  • temp++;
  • }
  • temp = 0;
  • if(temp!=hundreds)
  • {
  • if(hundreds==1) strcpy(rHundreds, "C");
  • if(hundreds==2) strcpy(rHundreds, "CC");
  • if(hundreds==3) strcpy(rHundreds, "CCC");
  • if(hundreds==4) strcpy(rHundreds, "CD");
  • if(hundreds==5) strcpy(rHundreds, "D");
  • if(hundreds==6) strcpy(rHundreds, "DC");
  • if(hundreds==7) strcpy(rHundreds, "DCC");
  • if(hundreds==8) strcpy(rHundreds, "DCCC");
  • if(hundreds==9) strcpy(rHundreds, "CM");
  • }
  • temp = 0;
  • if(temp!=tens)
  • {
  • if(tens==1) strcpy(rTens, "X");
  • if(tens==2) strcpy(rTens, "XX");
  • if(tens==3) strcpy(rTens, "XXX");
  • if(tens==4) strcpy(rTens, "XL");
  • if(tens==5) strcpy(rTens, "L");
  • if(tens==6) strcpy(rTens, "LX");
  • if(tens==7) strcpy(rTens, "LXX");
  • if(tens==8) strcpy(rTens, "LXXX");
  • if(tens==9) strcpy(rTens, "XC");
  • }
  • temp = 0;
  • if(temp!=ones)
  • {
  • if(ones==1) strcpy(rO, "I");
  • if(ones==2) strcpy(rO, "II");
  • if(ones==3) strcpy(rO, "III");
  • if(ones==4) strcpy(rO, "IV");
  • if(ones==5) strcpy(rO, "V");
  • if(ones==6) strcpy(rO, "VI");
  • if(ones==7) strcpy(rO, "VII");
  • if(ones==8) strcpy(rO, "VIII");
  • if(ones==9) strcpy(rO, "IX");
  • }
  • printf( "\nRomain : %s%s%s%s", rThousands, rHundreds , rTens , rO);
  • printf( "\n\n");
  • strcpy(rO, "");
  • strcpy(rTens, "");
  • strcpy(rHundreds, "");
  • strcpy(rThousands, "");
  • }
  • main();
  • }
  • void arabic()
  • {
  • char a[15];
  • int p,i,rom,flag,x,rep;
  • do{
  • printf("Entrez Romain Nombre :");
  • scanf("%s",a);
  • for(x=0,p=0,flag=0,rom=0,i=strlen(a)-1; i>=0; i--) {
  • if (a[i]=='i' || a[i]=='I') x=1;
  • if (a[i]=='v' || a[i]=='V') x=5;
  • if (a[i]=='x' || a[i]=='X') x=10;
  • if (a[i]=='l' || a[i]=='L') x=50;
  • if (a[i]=='c' || a[i]=='C') x=100;
  • if (a[i]=='d' || a[i]=='D') x=500;
  • if (a[i]=='m' || a[i]=='M') x=1000;
  • if (x<p) flag = -1;
  • else flag = 1;
  • rom= rom+(x*flag);
  • p=x;
  • }
  • printf("valeur numerique -->>> : %d",rom);
  • printf("\nEncore -1; autre touche - revinir dans menu\n"); scanf("%d",&rep);
  • }while(rep==1);
  • main();
  • }
  • main()
  • {
  • char lettre;
  • printf("\n *****************************\n");
  • printf(" * A R A B I Q U E - R O M A I N *\n");
  • printf( " *C O N V E R T I O N*\n");
  • printf(" *****************************\n");
  • printf("Conversion ARABIC-->>>ROMAIN: appuez A\n");
  • printf("Conversion ROMAIN-->>>ARABIC: appuez R\n");
  • printf("Sortir: appuez Q\n"); scanf("%c",&lettre); lettre=toupper(lettre);
  • if(lettre!='A'&&lettre!='R'&&lettre!='Q')
  • do{
  • printf("\nVotre choix dans menu,s.v.p.: A,R,Q: \n");scanf("%c",&lettre); lettre=toupper(lettre);
  • }while(lettre!='A'&&lettre!='R'&&lettre!='Q');
  • if (lettre=='A') arabic();
  • if (lettre=='R') roman();
  • else printf("\nMerci et au revoir!");
  • }
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h> 

void roman()

    {
    	
    	int ones, tens, hundreds, thousands, temp, input, x;
    	char rO[100] = "";
    	char rTens[100] = "";
    	char rHundreds[100] = "";
    	char rThousands[100] = "";
    	char *rTemp;
    	
    	
    	for(;;)


        	{
                        printf( "Votre nombre: (si 0 - revenir dans menu)  ");
        		scanf("%d",& input);
                                        if(input==0)  break;
        		printf( "\n\nArabic %d: ",input);
        		       		thousands = input/1000;
        		hundreds = (input-(thousands*1000))/100;
        		tens= (input-(thousands*1000 + hundreds*100))/10;
        		ones= (input-(thousands*1000 + hundreds*100 + tens*10));
        		temp = 0;
        		
        	while(temp!=thousands)


            	{
            		rTemp = "M";
            		strcat(rThousands, rTemp);
            		temp++;
            	}
            	
            	temp = 0;
            	
            	if(temp!=hundreds)


                	{
                		if(hundreds==1) strcpy(rHundreds, "C");
                		if(hundreds==2) strcpy(rHundreds, "CC");
                		if(hundreds==3) strcpy(rHundreds, "CCC");
                	if(hundreds==4) strcpy(rHundreds, "CD");
                		if(hundreds==5) strcpy(rHundreds, "D");
                		if(hundreds==6) strcpy(rHundreds, "DC");
                		if(hundreds==7) strcpy(rHundreds, "DCC");
                		if(hundreds==8) strcpy(rHundreds, "DCCC");
                		if(hundreds==9) strcpy(rHundreds, "CM");
                	}
                	
              
                	temp = 0;
                	
              
                	if(temp!=tens)


                    	{
                    		if(tens==1) strcpy(rTens, "X");
                    		if(tens==2) strcpy(rTens, "XX");
                    		if(tens==3) strcpy(rTens, "XXX");
                    		if(tens==4) strcpy(rTens, "XL");
                    		if(tens==5) strcpy(rTens, "L");
                    		if(tens==6) strcpy(rTens, "LX");
                    		if(tens==7) strcpy(rTens, "LXX");
                    		if(tens==8) strcpy(rTens, "LXXX");
                    		if(tens==9) strcpy(rTens, "XC");
                    	}
                    	
              
                    	temp = 0;
                    	
                    	
                    	if(temp!=ones)


                        	{
                        		if(ones==1) strcpy(rO, "I");
                        		if(ones==2) strcpy(rO, "II");
	                        	if(ones==3) strcpy(rO, "III");
                        		if(ones==4) strcpy(rO, "IV");
                        		if(ones==5) strcpy(rO, "V");
                        		if(ones==6) strcpy(rO, "VI");
                        		if(ones==7) strcpy(rO, "VII");
                        		if(ones==8) strcpy(rO, "VIII");
                        		if(ones==9) strcpy(rO, "IX");
                        	}
                        	
                        	
                        	printf( "\nRomain : %s%s%s%s", rThousands, rHundreds , rTens , rO);
                        		printf( "\n\n");
                        	
                        	strcpy(rO, "");
                        	strcpy(rTens, "");
                        	strcpy(rHundreds, "");
                        	strcpy(rThousands, "");
                    }
                    	
   
                         main();         
                        
                }

void arabic()
    {
    char a[15]; 
    int p,i,rom,flag,x,rep;
do{    
printf("Entrez  Romain Nombre :"); 	
    scanf("%s",a);
    for(x=0,p=0,flag=0,rom=0,i=strlen(a)-1; i>=0; i--)        {
        	if (a[i]=='i' || a[i]=='I') x=1; 
                  if (a[i]=='v' || a[i]=='V') x=5; 
        	if (a[i]=='x' || a[i]=='X') x=10; 
        	if (a[i]=='l' || a[i]=='L') x=50; 
        	if (a[i]=='c' || a[i]=='C') x=100; 
        	if (a[i]=='d' || a[i]=='D') x=500;
        	if (a[i]=='m' || a[i]=='M') x=1000; 
        	
        	if (x<p) flag = -1; 
        	else flag = 1;
        
                rom= rom+(x*flag);
                p=x;    
        	}
        printf("valeur numerique -->>> : %d",rom);
     printf("\nEncore -1; autre touche - revinir  dans menu\n"); scanf("%d",&rep);  
    }while(rep==1);
 main();
}


main()
{
char lettre;
printf("\n *****************************\n");
    	printf(" * A R A B I Q U E - R O M A I N *\n");
    	printf( "      *C O N V E R T I O N*\n");
                  printf(" *****************************\n");


printf("Conversion ARABIC-->>>ROMAIN: appuez A\n");
printf("Conversion ROMAIN-->>>ARABIC: appuez R\n");
printf("Sortir: appuez Q\n"); scanf("%c",&lettre); lettre=toupper(lettre);
if(lettre!='A'&&lettre!='R'&&lettre!='Q')
do{
 printf("\nVotre choix dans menu,s.v.p.: A,R,Q:   \n");scanf("%c",&lettre); lettre=toupper(lettre);
}while(lettre!='A'&&lettre!='R'&&lettre!='Q');
if (lettre=='A') arabic();
if (lettre=='R') roman();
else printf("\nMerci et au revoir!");

}



 Sources du même auteur

Source avec une capture FACTORIELLE QUI MARCHE JUSQU'A 415 CHIFFRES
Source avec Zip Source avec une capture EXAMPLE COMPLET DE BD EN C (FILES BINAIRES)

 Sources de la même categorie

Source avec Zip [C] WD_STRING V2.2 par cyberripper
Source avec Zip LES STRING EN C, AFFECTATION, CONCATÉNATION, SPLIT, ... par appranting
Source avec Zip [C] WD_STRING V1.9 par cyberripper
Source avec Zip LIBRAIRIE LANGUAGES par astro53
FONCTION : CHAR * AJUSTERTAILLECHAINE() par Rockanos

Commentaires et avis

Commentaire de kjus le 10/07/2002 13:50:04

Pour info, j'en ai fait un ici :
http://www.cppfrance.com/article.aspx?Val=674
spa dur ;)

Commentaire de natpoitiers le 10/07/2002 16:54:34

Dear kjus,
1.mon code arab--&gt;&gt;roma et roma--&gt;arab
2.J'ai pas assez du temps pour verifier toutes les sources ici. Sorry...
3.C'est pas mal si il y a plusier. solutions pour 1 seul problem. simple.
Hi, et merci pour lien.

Commentaire de kjus le 10/07/2002 18:00:17

ce n'était pas du tout une critique, mais seulement une information...
(It was not at all critics, but only an information for those who want to do a roman-arab program)

Commentaire de guguy le 10/07/2002 19:05:58

Moi je préfère la version de natpoitiers ;)

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
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 : 1,373 sec (3)

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