Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- //Write an expression that checks for given integer if its third digit from right-to-left is 7
- class ThirdDigitIs7
- {
- static void Main()
- {
- uint intToCheck;
- int needle = 7;
- Console.WriteLine("Provide an positive integer to check:");
- while(!uint.TryParse(Console.ReadLine(),out intToCheck))
- {
- Console.WriteLine("Please, enter valid integer.");
- }
- int thirdIntInDigit = Convert.ToInt32(Math.Floor(intToCheck / Math.Pow(10, 2) % 10));
- Console.WriteLine("3rd digit in {0} is 7? {1}", intToCheck, (thirdIntInDigit == needle)?"True":"False");
- Console.WriteLine("\nPress any key to exti.");
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement