문제
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
'백준 알고리즘' 카테고리의 다른 글
<백준 알고리즘> 3052번: 나머지 (0) | 2020.07.08 |
---|---|
<백준 알고리즘> 10996번: 별 찍기 - 21 (0) | 2020.07.08 |
<백준 알고리즘> 1546번: 평균 (0) | 2020.07.08 |
<백준 알고리즘> 10809번: 알파벳 찾기 (0) | 2020.07.08 |
<백준 알고리즘> 10828번: 스택 (0) | 2020.07.07 |