Advertisement
AlphaPenguino

decimal_roman_php

May 15th, 2024
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <?php
  2.  
  3. $input = readline();
  4.  
  5. function decimal_roman($num) {
  6.    
  7.     $output = "";
  8.     $roman_value = array("M"=>1000,
  9.                         "CM"=>900,
  10.                         "D"=>500,
  11.                         "CD"=>400,
  12.                         "C"=>100,
  13.                         "XC"=>90,
  14.                         "L"=>50,
  15.                         "LX"=>40,
  16.                         "X"=>10,
  17.                         "IX"=>9,
  18.                         "V"=>5,
  19.                         "IV"=>4,
  20.                         "I"=>1
  21.                         );
  22.    
  23.     foreach ($roman_value as $key => $value) {
  24.         while($num>=$value) {
  25.             $output .= $key;
  26.             $num -= $value;
  27.         }
  28.     }
  29.     return $output;
  30. }
  31. echo decimal_roman($input);
  32.  
  33.  
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement