HP Forums
Integer to Roman number - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Integer to Roman number (/thread-1612.html)



Integer to Roman number - LarsF - 06-14-2014 08:59 AM

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;