Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp12
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = 7;
- int f = factorial(n);
- Console.WriteLine("* * * * * * * f a c t o r i a l * * * * * * *");
- Console.WriteLine("final result: factorial({0}) = {1}", n, f);
- int x = 3219786;
- int d = 2;
- Console.WriteLine("\n\n* * * * * * * * h a s * * * * * * * *");
- if (has(x, d))
- Console.WriteLine("{0} has a digit equals to {1}", x, d);
- else
- Console.WriteLine("{0} does not have a digit equals to {1}", x, d);
- }
- public static bool has(int n, int k)
- {
- Console.WriteLine("start searching in {0} for {1}", n, k);
- if (n == 0)
- {
- Console.WriteLine("stop searching. {0} was not found", k);
- return false;
- }
- int a = n % 10; // ahad only
- int rest = n / 10; // number without ahad
- if (k == a)
- {
- Console.WriteLine("{0} starts with the digit {1}", n, k);
- return true;
- }
- return has(rest, k);
- }
- public static int factorial(int n)
- {
- Console.WriteLine("start factorial with {0}", n);
- if (n == 0)
- {
- Console.WriteLine("factorial({0})={1}", n, 1);
- return 1;
- }
- int res = n * factorial(n - 1);
- Console.WriteLine("factorial({0})={1}", n, res);
- return res;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement