HP Forums

Full Version: Integer to Roman number
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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;
Reference URL's