0/5 (4 avis)
Snippet vu 6 255 fois - Téléchargée 37 fois
#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!"); }
10 juil. 2002 à 19:05
10 juil. 2002 à 18:00
(It was not at all critics, but only an information for those who want to do a roman-arab program)
10 juil. 2002 à 16:54
1.mon code arab-->>roma et roma-->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.
10 juil. 2002 à 13:50
http://www.cppfrance.com/article.aspx?Val=674
spa dur ;)
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.