Created
February 26, 2014 00:18
-
-
Save tenor/9220821 to your computer and use it in GitHub Desktop.
These programs display a list of the names of single digits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This program outputs the names of a given list of digits backwards | |
// | |
string GetDigitName(int digit) | |
{ | |
switch(digit) | |
{ | |
case 0: return "zero"; | |
case 1: return "one"; | |
case 2: return "two"; | |
case 3: return "three"; | |
case 4: return "four"; | |
case 5: return "five"; | |
case 6: return "six"; | |
case 7: return "seven"; | |
case 8: return "eight"; | |
case 9: return "nine"; | |
default: | |
throw new ArgumentException(digit + "is not a digit."); | |
} | |
} | |
List<int> digits = new List<int>(new int[]{0,1,2,3,4,5,6,7,8,9}); | |
int index; | |
while(digits.Count > 0) | |
{ | |
index = digits.Count - 1; | |
Console.WriteLine(GetDigitName(digits[index])); | |
digits.RemoveAt(index); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This program outputs the names of a given list of digits in a random order | |
// | |
string GetDigitName(int digit) | |
{ | |
switch(digit) | |
{ | |
case 0: return "zero"; | |
case 1: return "one"; | |
case 2: return "two"; | |
case 3: return "three"; | |
case 4: return "four"; | |
case 5: return "five"; | |
case 6: return "six"; | |
case 7: return "seven"; | |
case 8: return "eight"; | |
case 9: return "nine"; | |
default: | |
throw new ArgumentException(digit + "is not a digit."); | |
} | |
} | |
List<int> digits = new List<int>(new int[]{0,1,2,3,4,5,6,7,8,9}); | |
Random rnd = new Random(); | |
int index; | |
while(digits.Count > 0) | |
{ | |
index = rnd.Next(digits.Count); | |
Console.WriteLine(GetDigitName(digits[index])); | |
digits.RemoveAt(index); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment