문제
https://www.acmicpc.net/problem/10872
10872번: 팩토리얼
0보다 크거나 같은 정수 N이 주어진다. 이때, N!을 출력하는 프로그램을 작성하시오.
www.acmicpc.net
해결한 방법
n에서 1씩 빼주면서 n이 1이 될때까지 결과값에 곱해주었습니다.
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n;
cin >> n;
int result = 1;
while (n) {
result *= n;
n--;
}
cout << result;
return 0;
}
'알고리즘 공부 > 백준' 카테고리의 다른 글
2004번 조합 0의 개수 with C++ (0) | 2022.07.12 |
---|---|
1676번 팩토리얼 0의 개수 with C++ (0) | 2022.07.11 |
6588번 골드바흐의 추측 with C++ (0) | 2022.07.11 |
1929번 소수 구하기 with C++ (0) | 2022.07.10 |
1978 소수 찾기 with C++ (0) | 2022.07.10 |