Advertisement
mzografski

3rdIs7

Mar 15th, 2014
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. //Write an expression that checks for given integer if its third digit from right-to-left is 7
  8.  
  9. class ThirdDigitIs7
  10. {
  11.     static void Main()
  12.     {
  13.         uint intToCheck;
  14.         int needle = 7;
  15.         Console.WriteLine("Provide an positive integer to check:");
  16.         while(!uint.TryParse(Console.ReadLine(),out intToCheck))
  17.         {
  18.             Console.WriteLine("Please, enter valid integer.");
  19.         }
  20.         int thirdIntInDigit = Convert.ToInt32(Math.Floor(intToCheck / Math.Pow(10, 2) % 10));
  21.        
  22.         Console.WriteLine("3rd digit in {0} is 7? {1}", intToCheck, (thirdIntInDigit == needle)?"True":"False");
  23.  
  24.         Console.WriteLine("\nPress any key to exti.");
  25.         Console.ReadKey();
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement