Created
March 3, 2016 21:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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