Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class LastDigitAsAWord
- {
- //Write a method that returns the last digit of given integer
- //as an English word.
- //Examples: 512 "two", 1024 "four", 12309 "nine".
- static void WordLastDigit(int lastDigit) // In this method we print the last digit as a word.
- {
- string[] array = new string[] {"Zero",
- "One", "Two", "Three", "Four",
- "Five", "Six", "Seven", "Eight",
- "Nine", "Ten"
- };
- Console.WriteLine("The last digit is {0} !", array[lastDigit]);
- }
- private static int GetLastDigit() // here we calculate the last digit
- {
- Console.Write("Enter a number: ");
- int number = int.Parse(Console.ReadLine());
- int reminder = number % 10;
- return reminder;
- }
- static void Main()
- {
- WordLastDigit(GetLastDigit()); // execute the two methods.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement