"깊이"가 다른 게임개발자 허민영

유저에서 게임까지, 철학에서 코딩까지, 본질을 보는 게임개발

내일배움캠프

[Unity 7기] 팩토리얼 계산기

허민영 2024. 12. 27. 17:34
Console.WriteLine("팩토리얼 계산할 숫자를 입력하세요");
string answer = Console.ReadLine();
uint iAnswer;
bool Success = uint.TryParse(answer, out iAnswer);
if (Success==true)
{
    if(iAnswer > 12)
    {
        Console.WriteLine("값이 너무 큽니다.");
    }
    else
    {
        uint i = iAnswer;
        uint factorial = 1;
        while (i >= 1)
        {
            factorial = factorial * i;
            i--;
        }
        Console.WriteLine("Enter a number:" + answer + "\nFactorial of" + answer + "is" + factorial);
    }
}
else
{
    Console.WriteLine("양의 정수를 입력해주세요");
}