Skip to content

Instantly share code, notes, and snippets.

@vdonchev
Created March 3, 2016 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdonchev/e5a5bc32a85fce4cbc15 to your computer and use it in GitHub Desktop.
Save vdonchev/e5a5bc32a85fce4cbc15 to your computer and use it in GitHub Desktop.
namespace SomeNumbers
{
using System;
public static class Program
{
private static readonly string[] NumbersInWords =
{
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"
};
public static void Main()
{
var num = int.Parse(Console.ReadLine());
var result = string.Empty;
if (num < 0 || num > 100)
{
result += "invalid number";
}
else if (num == 100)
{
result += "one hundred";
}
else
{
var firstNum = (num / 10) % 10;
var secondNum = num % 10;
if (num > 20)
{
result += NumbersInWords[(firstNum - 2) + 20];
if (secondNum != 0)
{
result += " " + NumbersInWords[secondNum % 10];
}
}
else
{
result += NumbersInWords[num];
}
}
Console.WriteLine(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment