Post Reply 
Integer to Roman number
06-14-2014, 08:59 AM
Post: #1
Integer to Roman number
Small program that converts a integer to Roman number, inspired from a thread in the General Forum

Code:

EXPORT Roman()
BEGIN
  LOCAL R:="";
  L1:={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
  L2:={1000,900,500,400,100,90,50,40,10,9,5,4,1};
  
  PRINT();

  INPUT(L,"Roman numbers","Integer");
  A:=L;  //Remember input
  FOR I FROM 1 TO SIZE(L2) DO
    T:=IP(L/L2(I));
    L:=L-T*L2(I);
    FOR J FROM 1 TO T DO
      R:=R + L1(I); 
    END;  
  END;
  PRINT(A+" = " + R);
END;
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)