3
06/11/2024 6:37 pm
Topic starter
Please help me write an expression that checks for given integer if its third digit from right-to-left is 7.
Examples:
1 Answer
2
06/11/2024 6:38 pm
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 } }