SHARE
TWEET

Numbers To 100 Words

MartinGeorgiev Nov 25th, 2018 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $n = intval(readline());
  4.  
  5. $digits = [ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"
  6. ];
  7. $tens = [
  8.     "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"
  9. ];
  10. $rounds = [
  11.     "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"
  12. ];
  13.  
  14. if ($n < 0 || $n > 100) {
  15.     echo "invalid number";
  16. } else if ($n >= 0 && $n <= 9) {
  17.     echo  $digits[$n];
  18. } else if ($n >= 10 && $n <= 19) {
  19.    echo $tens[$n - 10];
  20. } else if ($n >= 20 && $n <= 99) {
  21.     if ($n % 10 == 0) {
  22.         echo $rounds[$n / 10 - 2];
  23.     } else {
  24.         echo  $rounds[$n / 10 - 2]." ". $digits[$n % 10];
  25.     }
  26. } else {
  27.     echo ("one hundred");
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top