Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2016
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace NumToWords
  8. {
  9. class Program
  10. {
  11. static void NumToWord(int a)
  12. {
  13. string[] ZeroToNineteen = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
  14. "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
  15. string[] Tens = { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety", "one hundred"};
  16.  
  17. int toTens = a / 10 - 2;
  18. int nineteen = a % 10;
  19.  
  20. if (a >= 0 && a <= 100)
  21. {
  22. if (a < 20)
  23. {
  24. Console.WriteLine(ZeroToNineteen[a]);
  25. }
  26. else if (a >= 20 && a % 10 == 0)
  27. {
  28. Console.WriteLine(Tens[toTens]);
  29. }
  30. else
  31. {
  32. Console.WriteLine(Tens[toTens] + " " + ZeroToNineteen[nineteen]);
  33. }
  34. }
  35. else
  36. {
  37. Console.WriteLine("invalid number");
  38. }
  39. }
  40. static void Main(string[] args)
  41. {
  42.  
  43. var input = int.Parse(Console.ReadLine());
  44. NumToWord(input);
  45.  
  46.  
  47.  
  48.  
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement