Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 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 _18.NumbersToWords
  8. {
  9. class numsTOwords
  10. {
  11. static void Main(string[] args)
  12. {
  13. int number = int.Parse(Console.ReadLine());
  14. string words="";
  15. string[] ones = { "zero","one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
  16. string[] teens = { "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
  17. string[] tens = {"ten","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};
  18. if (number<0)
  19. {
  20. Console.WriteLine("Invalid number");
  21. }
  22. else if (number>100)
  23. {
  24. Console.WriteLine("invalid number");
  25. }
  26. else if (number==100)
  27. {
  28. Console.WriteLine("one hundred");
  29. }
  30. else if (number<10)
  31. {
  32. words += ones[number];
  33. Console.WriteLine(words);
  34. }
  35. else if (number % 10 == 0)
  36. {
  37. words += tens[(number / 10) - 1];
  38. Console.WriteLine(words);
  39. }
  40. else if (number<20)
  41. {
  42. words += teens[number - 11];
  43. Console.WriteLine(words);
  44. }
  45. else
  46. {
  47. int i = number / 10;
  48. var j = number % 10;
  49. words += tens[i - 1] + " "+ones[j];
  50. Console.WriteLine(words);
  51. }
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement