|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
EXAMPLE CLASSIQUE: CONVERTION ENTIER EN CHIFFRE ROMAINE ET <<-- (LANG- C )
Information sur la source
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
Sources de la même categorie
Commentaires et avis
|
Comparez les prix Nouvelle version
|