/******************************************************* n-choose-k.ch Combinations: n choose k Use this program to have students check solutions to exercises they are already working on related to combinations (n choose k). Students may also analyze or fill parts of the program to reinforce their understanding. ************************************************************ Copyright 2014 SoftIntegration Inc. http://www.softintegration.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 *******************************************************/ // we need a factorial function double factorial(double n) { if (n == 0) return 1; else return (n * factorial(n-1)); } // initialize variables for the program double n, k; double numer, denom, result; // get the input printf("nCk\n"); printf("what is n? "); scanf("%lf", &n); printf("what is k? "); scanf("%lf", &k); //nCk = n! / (n-k)!*k! numer = factorial(n); denom = factorial(n-k) * factorial(k); result = numer/denom; printf("%.2lfC%.2lf = %.2lf\n", n, k, result);