SHARE
TWEET

Untitled

a guest May 28th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Number0To100
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] belowTwenty = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
  14.             string[] roundNumbers = { "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
  15.             int number = int.Parse(Console.ReadLine());
  16.             //Corner cases
  17.             if (number == 100)
  18.             {
  19.                 Console.WriteLine("one hundred");
  20.                 return;
  21.             }
  22.             if (number < 0 || number > 100)
  23.             {
  24.                 Console.WriteLine("invalid number");
  25.                 return;
  26.             }
  27.             if (number < 20)
  28.             {
  29.                 Console.WriteLine(belowTwenty[number]);
  30.                 return;
  31.             }
  32.  
  33.             int secondDigit = number % 10;
  34.             number = number / 10;
  35.  
  36.             if (secondDigit == 0)
  37.             {
  38.                 Console.WriteLine(roundNumbers[number]);
  39.             }
  40.             else
  41.             {
  42.                 Console.WriteLine(roundNumbers[number] + " " + belowTwenty[secondDigit]);
  43.             }
  44.         }
  45.     }
  46. }
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