[Solved] Check if the third digit is 7?

  

3
Topic starter

Please help me write an expression that checks for given integer if its third digit from right-to-left is 7.

Examples:

check if the third number is 7 (seven)

1 Answer
2

Here is my solution:

using System;
 
class Program
{
    static void Main()
    {
        long n = long.Parse(Console.ReadLine());
 
        long check100 = n / 100;//Dividing the number by 100 >> and the 3rd number is the FIRST NOW
        long checkRest = check100 % 10;//using module division and getting the leftover number 
 
        bool result = (checkRest == 7);//checking whether the leftover number is 7 or not with bool expression
 
        Console.WriteLine("Third number 7? {0}", result);//printing the result
    }
}
Share: