문제

0보다 크거나 같은 정수 N이 주어진다. 이때, N!을 출력하는 프로그램을 작성하시오.

입력

첫째 줄에 정수 N(0 ≤ N ≤ 12)가 주어진다.

출력

첫째 줄에 N!을 출력한다.

예제 입력 1

10

예제 출력 1

3628800

더보기

Solution

#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	long long int N, *factorial=NULL;

	scanf("%lld", &N);
	factorial=(long long int *)malloc((N+1)*sizeof(long long int));

	factorial[0]=1;
	for(int i=1;i<=N;i++)
		factorial[i]=i*factorial[i-1];

	printf("%lld\n", factorial[N]);

	free(factorial);
	return 0;
}
728x90

+ Recent posts