[백준] C# : 팩토리얼 (10872번)

ssu_hyun·2022년 7월 9일
0

Data Structure & Algorithm

목록 보기
18/67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Baekjoon
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int result = 1;

            for (int i=1; i <= n; i++)
            {
                result *= i;
            }

            Console.WriteLine(result);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Baekjoon
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(Fac(n));
        }

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


0개의 댓글