백준 27433 c++

magicdrill·2024년 4월 18일

백준 문제풀이

목록 보기
326/673

백준 27433 c++

#include <iostream>

using namespace std;

int input(int lower, int upper);
long long int factorial(int num);

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int N;
	
	N = input(0, 20);
	cout  << factorial(N) << "\n";

	return 0;
}

int input(int lower, int upper)
{
	//cout << "input()" << endl;
	int A;

	while (1)
	{
		cin >> A;
		if (A >= lower && A <= upper)
		{
			break;
		}
		else
		{
			;
		}
	}

	return A;
}

long long int factorial(int num)//20!은 오버플로우 발생
{
	if (num == 0)
	{
		return 1;
	}
	else
	{
		return num * factorial(num - 1);
	}
}

0개의 댓글