#include <stdio.h> void print_number(int); void main() { int number=-1; while (number<1 || number>99) { printf("숫자를 입력해주세요.>>"); scanf("%d",&number); } printf ("결과 >> "); print_number(number); } void print_number(int number) { const int DATA_SIZE=3; const int NUMBER_DATA[DATA_SIZE]={1,5,10}; const char CHAR_DATA[DATA_SIZE][3]={"Ⅰ","Ⅴ","Ⅹ"}; for (register int i=DATA_SIZE-1; i>=0; --i) { if (i+1<DATA_SIZE && number==NUMBER_DATA[i+1]-1) { printf("%s",CHAR_DATA[0]); printf("%s",CHAR_DATA[i+1]); break; } while (number>=NUMBER_DATA[i]) { number-=NUMBER_DATA[i]; printf ("%s",CHAR_DATA[i]); } } }
-module(pr_9). -export([getString/1]). getString(Num) when 0 == Num -> ""; getString(Num) when 10 < Num -> "X " ++ getString(Num - 10); getString(Num) -> lists:nth(Num, ["I ", "II ", "III ", "IV ", "V ", "VI", "VII", "VIII", "IX"]).
3> c(pr_9). {ok,pr_9} 4> pr_9:getString(43). "X X X X III " 5> pr_9:getString(38). "X X X VIII" 6> pr_9:getString(24). "X X IV "