[백준 27433] 팩토리얼 2 (C#, C++) - soo:bak
작성일 :
문제 링크
설명
입력으로 주어지는 정수 n 에 대하여 n 팩토리얼(n!) 을 계산하여 출력하는 문제입니다.
n!은 n * (n - 1) * (n - 2) * ... * 2 * 1 로 정의되며, 0! 은 1 로 정의됩니다.
Code
[ C# ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
namespace Solution {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine()!);
long factorial = 1;
for (int i = 1; i <= n; i++)
factorial *= i;
Console.WriteLine(factorial);
}
}
}
[ C++ ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
ll factorial = 1;
for (int i = 1; i <= n; i++)
factorial *= i;
cout << factorial << "\n";
return 0;
}