백준/C
[BaeKJoon/C] 백준11050 c 이항 계수 1
coose
2021. 5. 18. 18:41
반응형
https://www.acmicpc.net/problem/11050
11050번: 이항 계수 1
첫째 줄에 \(N\)과 \(K\)가 주어진다. (1 ≤ \(N\) ≤ 10, 0 ≤ \(K\) ≤ \(N\))
www.acmicpc.net
문제
자연수 N과 정수 K가 주어졌을 때 N과K에 대한 이항계수를 구하는 프로그램을 작성하시오
풀이
코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#include <stdio.h>
int main() {
int a, b;
int mul1 = 1, mul2 = 1, mul3 = 1;
scanf("%d %d", &a, &b);
for (int i = 1; i <= a; i++) {
mul1 *= i;
}
for (int j = 1; j <= b; j++) {
mul2 *= j;
}
for (int k = 1; k <= a - b; k++) {
mul3 *= k;
}
printf("%d", mul1 / (mul2 * mul3));
}
|
cs |
반응형