Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class IsThirdDigitSeven
- {
- static void Main()
- {
- int number = 234;
- bool isSeven = FindWithRecursion(number);
- if(appearance != 0)
- {
- if(isSeven)
- {
- Console.WriteLine("Is thrid digit Seven: " + isSeven + " Appearance: " + appearance);
- }
- else
- {
- Console.WriteLine("Appearance: " + appearance + " but not at third position");
- }
- }
- else
- {
- Console.WriteLine("Number not consist digit Seven at all");
- }
- }
- static int appearance = 0;
- static bool FindWithRecursion(int number)
- {
- if(number % 10 == 7)
- {
- appearance++;
- }
- if(number / 10 == 0)//делима на 10 за последната цифра, и така се предпазваме да не влезнем по надолу
- {
- return false;
- }
- else if((number % 10 == 7) && (number / 1000) == 0)
- {
- return true;
- }
- return FindWithRecursion(number / 10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment