Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace NumToWords
- {
- class Program
- {
- static void NumToWord(int a)
- {
- string[] ZeroToNineteen = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
- "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
- string[] Tens = { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety", "one hundred"};
- int toTens = a / 10 - 2;
- int nineteen = a % 10;
- if (a >= 0 && a <= 100)
- {
- if (a < 20)
- {
- Console.WriteLine(ZeroToNineteen[a]);
- }
- else if (a >= 20 && a % 10 == 0)
- {
- Console.WriteLine(Tens[toTens]);
- }
- else
- {
- Console.WriteLine(Tens[toTens] + " " + ZeroToNineteen[nineteen]);
- }
- }
- else
- {
- Console.WriteLine("invalid number");
- }
- }
- static void Main(string[] args)
- {
- var input = int.Parse(Console.ReadLine());
- NumToWord(input);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement