Hi All,

This program is returning output as string, lets go to an example. Such as, if you enter a number 19, then this program will return "Nineteen". So shall we do it????

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace ConvertNumericToString
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. do
  12. {
  13. Console.WriteLine("Please enter the number..");
  14. int intNum = Convert.ToInt32(Console.ReadLine());
  15. Console.WriteLine(CheckAndDisplayString(intNum));
  16. Console.WriteLine("Do you want to continue ..Y/N?");
  17. } while (Console.ReadLine().ToLower() == "y");
  18. Console.ReadLine();
  19. }
  20. private static string CheckAndDisplayString(int intNum)
  21. {
  22. try
  23. {
  24. var str1To19 = new string[] { "zero", "one", "two",
  25. "three", "four", "five", "six",
  26. "seven", "eight", "nine", "ten",
  27. "eleven", "twelve", "thirteen",
  28. "fourteen", "fifteen", "sixteen", "seventeen",
  29. "eighteen", "nineteen"};
  30. var strMultipleOfTen = new string[] { "twenty", "thirty",
  31. "forty", "fifty", "sixty", "seventy",
  32. "eighty", "ninety" };
  33. //If the Number is zero return null
  34. if (intNum == 0)
  35. return "zero";
  36. //check the 100 digit
  37. string strResult = "";
  38. int intDigit;
  39. if (intNum > 100)
  40. {
  41. intDigit = intNum / 100;
  42. intNum = intNum % 100;
  43. strResult = str1To19[intDigit] + "hundred";
  44. }
  45. if (intNum == 0)
  46. return strResult.Trim();
  47. if (intNum < 20)
  48. strResult += " " + str1To19[intNum];
  49. else
  50. {
  51. //handles 10 digit
  52. intDigit = intNum / 10;
  53. intNum = intNum % 10;
  54. strResult += " " + strMultipleOfTen[intDigit - 2];
  55. if (intNum > 0)
  56. strResult += " " + str1To19[intNum];
  57. }
  58. return strResult;
  59. }
  60. catch
  61. {
  62. return "The value you entered is not applicable..";
  63. }
  64. }
  65. }
  66. }
See the output here:

output

Thank you :)