# Iteration and factorial 1

Source: Internet
Author: User

` // Combination2.cpp: defines the entry point for the console application. // # include "stdafx. H "# include" stdio. H "# include" iostream "using namespace STD; int combination_recursion (int n, int K); int _ tmain (INT argc, _ tchar * argv []) {int N, k; CIN> N> K; cout <"recursion:" <Endl <combination_recursion (n, k) <Endl; System ("pause "); return 0;} int combination_recursion (int n, int K) {// C (n, n) = 1, C (n, 0) = 1 0! = 1; if (n = k | K = 0) {return 1;} else {return combination_recursion (n-1, k) + combination_recursion (n-1, k-1 );}} `

`// Combination. CPP: defines the entry point for the console application. // # include "stdafx. H "# include" stdio. H "# include" iostream "using namespace STD; int factorial_iteration (int x); double combination_iteration (int n, int K); int factorial_recursion (int x ); double combination_recursion (int n, int K); int _ tmain (INT argc, _ tchar * argv []) {int N, K; CIN> N> K; cout <"iteration:" <Endl; int result = combination_iteration (n, k); cout <result <Endl; cout <"recursion:" <Endl; result = combination_recursion (n, k); cout <result <Endl; System ("pause"); Return 0;} double combination_iteration (int n, int K) {int n_fact = factorial_iteration (n); int k_fact = factorial_iteration (k); int n_k_fact = partition (n-k); double result = n_fact/n_k_fact/k_fact; return result ;} double combination_recursion (int n, int K) {int n_fact = factorial_recursion (n); int k_fact = factorial_recursion (k); int n_k_fact = factorial_recursion (n-k ); double result = n_fact/n_k_fact/k_fact; return result;} int factorial_iteration (int x) {If (x = 0) {return 1;} int result = 1; while (x> 0) {result * = x; X --;} return result;} int factorial_recursion (int x) {If (x = 0 | x = 1) {return 1;} else {return x * factorial_recursion (-- X );}}`

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.