Skip to content

Instantly share code, notes, and snippets.

@vdonchev vdonchev/0-100.cs
Created Mar 3, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.