본문 바로가기
IT/C#

C# (팩토리얼 재귀함수)

by hjshims 2021. 5. 13.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RoadBook.CsharpBasic.Chapter01.f0513
{
    class Factorial2
    {
        public void Run()
        {
            Console.WriteLine(Factorial(5));
        }

        static int Factorial(int n)
        {
            if(n==0 || n == 1)
            {
                return 1;
            }
            return n * Factorial(n-1);      //재귀함수
        }
    }
}