Advertisement
simonradev

Test

May 14th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. namespace _1000DaysAfterBirth
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Globalization;
  6.     using System.Linq;
  7.     using System.Text;
  8.     using System.Threading.Tasks;
  9.    
  10.     public class Program
  11.     {
  12.         public static void Main()
  13.         {
  14.             string[] firstNineteenNumbers = new string[]
  15.             {
  16.                 "Zero",
  17.                 "One",
  18.                 "Two",
  19.                 "Three",
  20.                 "Four",
  21.                 "Five",
  22.                 "Six",
  23.                 "Seven",
  24.                 "Eight",
  25.                 "Nine",
  26.                 "Ten",
  27.                 "Eleven",
  28.                 "Twelve",
  29.                 "Thirteen",
  30.                 "Fourteen",
  31.                 "Fifteen",
  32.                 "Sixteen",
  33.                 "Seventeen",
  34.                 "Eighteen",
  35.                 "Nineteen"
  36.             };
  37.            
  38.             string[] tens = new string[]
  39.             {
  40.                 "Twenty ",
  41.                 "Thirty ",
  42.                 "Forty ",
  43.                 "Fifty ",
  44.                 "Sixty ",
  45.                 "Seventy ",
  46.                 "Eighty ",
  47.                 "Ninety "
  48.             };
  49.  
  50.             StringBuilder test = new StringBuilder();
  51.             for (int numberInput = 0; numberInput <= 100; numberInput++)
  52.             {
  53.                 string result = string.Empty;
  54.                 if (numberInput >= 0 && numberInput <= 19)
  55.                 {
  56.                     result = firstNineteenNumbers[numberInput];
  57.                 }
  58.                 else if (numberInput >= 20 && numberInput < 100)
  59.                 {
  60.                     string secondNumber = numberInput % 10 == 0 ? string.Empty : firstNineteenNumbers[numberInput % 10];
  61.  
  62.                     result = (tens[numberInput / 10 - 2] + secondNumber);
  63.                 }
  64.                 else if (numberInput == 100)
  65.                 {
  66.                     result = "one hundred";
  67.                 }
  68.  
  69.                 test.AppendLine(result);
  70.             }
  71.  
  72.             Console.Write(test);
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement