Skip to content

Instantly share code, notes, and snippets.

@Nikola-Andreev
Created January 17, 2017 15:21
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 Nikola-Andreev/1cc5f1556862e14b39e6fbe38e6a39d2 to your computer and use it in GitHub Desktop.
Save Nikola-Andreev/1cc5f1556862e14b39e6fbe38e6a39d2 to your computer and use it in GitHub Desktop.
Number to 100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace numsTo100inText
{
class Program
{
static void Main(string[] args)
{
int num = int.Parse(Console.ReadLine());
string[] tonineteen = { "zero","one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
string[] toninety = { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
if (num < 0 )
{
Console.WriteLine("Invalid number");
}
else if (num > 100)
{
Console.WriteLine("Invalid number");
}
else if (num>=0 && num <= 19)
{
Console.WriteLine(tonineteen[num]);
}
else if (num>=20 && num < 100)
{
if (num%10 == 0)
{
Console.WriteLine(toninety[(num / 10) - 2]);
}
else
{
Console.WriteLine(toninety[(num / 10) - 2] +" "+ tonineteen[(num % 10)]);
}
}
else if (num == 100)
{
Console.WriteLine("one hundred");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment