[백준/C++] 11050 - 이항 계수 1

orangesnail·2025년 8월 13일

백준

목록 보기
139/169

https://www.acmicpc.net/problem/11050


구현하기

이항계수 공식만 알면 금방 구현할 수 있다.
팩토리얼을 main 내에서 하나하나 구하려면 코드가 너무 길어질 것 같아서 함수로 따로 만들어주었다.

#include <iostream>
using namespace std;

int fact(int a) {
    int b = 1;
    for (int i = 1; i <= a; i++) {
        b *= i;
    }
    return b;
}

int main() {
    int n, k;
    cin >> n >> k;

    int answer = fact(n) / (fact(k) * fact(n - k));

    cout << answer << endl;

    return 0;
}
profile
초보입니다. 피드백 환영합니다 😗

0개의 댓글