Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace kek
- {
- class Program
- {
- static int Fact_1(int n)
- {
- Console.WriteLine("Вызов " + n);
- int f = 1;
- if (n > 1) f = n * Fact_1(n - 1);
- Console.WriteLine("Подсчет при n = " + n + " Факт = " + f);
- return f;
- }
- static int Fact_2(int n)
- {
- int f = 1;
- if (n > 1) f = Fact_2(n - 1) * n;
- return f;
- }
- static void Fact_out(int n, out int f)
- {
- if (n > 1)
- {
- n--;
- Fact_out(n, out f);
- f *= (n + 1);
- }
- else f = 1;
- }
- static void Fact_ref(int n, ref int f)
- {
- if (n > 1)
- {
- f *= n;
- n--;
- Fact_ref(n, ref f);
- }
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Введите число для подсчета его факториала");
- int n = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine();
- Console.WriteLine("{0}! = {1}\n", n, Fact_1(n));
- Console.WriteLine("{0}! = {1}\n", n, Fact_2(n));
- int f;
- Fact_out(n, out f);
- Console.WriteLine("{0}! = {1}\n", n, f);
- f = 1;
- Fact_ref(n, ref f);
- Console.WriteLine("{0}! = {1}\n", n, f);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement