-
C] 두 자연수를 입력받아 nCr 출력Study/C 2008. 3. 21. 20:48This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// 두 자연수를 입력받아 nCr 출력 // nCr = n(n-1)...(n-r+1) / r!=r(r-1)...1 #include <stdio.h> int comb(int a, int b) { int i, j, n=1, r=1; for(i=a; i>=a-b+1; i--) n=n*i; for(j=b; j>=1; j--) r=r*j; return(n/r); } void main() { int n, r; printf("Input any number for n: "); scanf("%d", &n); printf("Input any number for r: "); scanf("%d", &r); printf("C(%d, %d) = %d\n", n, r, comb(n, r)); } 반응형'Study > C' 카테고리의 다른 글
C] 다섯 개의 문자형 변수에 저장되어 있는 값을 원형(circular)으로 이동(shift) (0) 2008.04.10 C] 0 입력할 때까지 입력받은 숫자들의 최소, 최대, 평균 (0) 2008.03.24 C] for문을 이용한 도형 찍기 (0) 2008.03.21 C] 이차방정식 근 구하기 (0) 2008.03.17 C] 1byte의 자연수를 반대방향의 2진수로 출력 (0) 2008.03.13