Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void toromai(char inp[],char outp[]) /* Arab számot alakít római számmá */
- {
- int a,n=0;
- char *romai;
- char egyesek[][10] = {"I","II","III","IV","V","VI","VII","VIII","IX"};
- char tizesek[][10] = {"X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
- char szazasok[][10] = {"C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
- char ezresek[][4] = {"M","MM","MMM"};
- n = strlen(inp);
- a = atoi(inp);
- romai=(char*)calloc(4*n,sizeof(char*));
- if(1<=a && a<4000)
- {
- if(n==4)
- {
- strcat(romai,ezresek[(a/1000)-1]);
- if(a%1000!=0)
- {
- a%=1000;
- if(9<a%1000 && a%1000<100) n--;
- if(1<=a%1000 && a%1000<10) n-=2;
- n--;
- }
- else {
- strcpy(outp,romai);
- }
- }
- if(n==3)
- {
- strcat(romai,szazasok[(a/100)-1]);
- if(a%100!=0)
- {
- a%=100;
- if(1<=a%100 && a%100<10) n--;
- n--;
- }
- else {
- strcpy(outp,romai);
- }
- }
- if(n==2)
- {
- strcat(romai,tizesek[(a/10)-1]);
- if(a%10!=0)
- {
- a%=10;
- n--;
- }
- else {
- strcpy(outp,romai);
- }
- }
- if(n==1) strcat(romai,egyesek[a-1]);
- else {
- strcpy(outp,romai);
- }
- }
- else {
- strcpy(outp,"#ERTEK!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement