Created
March 3, 2016 21:07
-
-
Save vdonchev/e5a5bc32a85fce4cbc15 to your computer and use it in GitHub Desktop.
This file contains 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