fork download
  1. //Run it on codeblocks or Orwell/Bloodshed Dev C++ (Any termianl based program)
  2.  
  3. #include <stdio.h> // Standard library for C input/output
  4. #include <stdlib.h> // Standard library definitions
  5. #define TERMINAL -9 // This is a macro that is defined globally
  6. // it is used to tell the program that the user is
  7. // done with their input.
  8. int main() // Main declaration with arguments
  9. {
  10. int userInput1,
  11. userInput2,
  12. nFact = 1,
  13. kFact = 1,
  14. n_k,
  15. nkFact = 1,
  16. combination;
  17.  
  18.  
  19.  
  20. do {
  21. printf("\nEnter the number of items in the list (n): ");
  22. scanf("%d", &userInput1);
  23. if ( userInput1 < 1 || userInput1 > 10 ) /* is n between 1 - 10 */
  24. printf("\n?Invalid input: Number must be between 1 and 10\n");
  25. else
  26. break;
  27. } while ( userInput1 < 1 || userInput1 > 10 );
  28.  
  29.  
  30.  
  31. /* As long as n>=1 program will loop the following n*n-1 */
  32.  
  33. int n;
  34. for ( n = userInput1; n > 1; n--) {
  35. nFact = ( nFact * n );
  36. }
  37.  
  38. printf("n! = %d", nFact);
  39.  
  40.  
  41. do {
  42. printf("\nEnter the number of items to choose (k): ");
  43. scanf("%d", &userInput2);
  44. if ( userInput2 < 1 || userInput2 > 10 ) /* is k between 1 - 10 */
  45. printf("\n?Invalid input: Number must be between 1 and 10\n");
  46. else
  47. break;
  48. } while ( userInput2 < 1 || userInput2 > 10 );
  49. int k;
  50. for ( k = userInput2; k > 1; k--) {
  51. kFact = ( kFact * k );
  52. }
  53.  
  54. printf("k! = %d", kFact);
  55. printf("n = %d k = %d", userInput1, userInput2);
  56. n_k = userInput1 - userInput2;
  57. while (n_k>=1)
  58. {
  59. nkFact = ( nkFact * n_k );
  60. n_k = ( n_k - 1 );
  61. }
  62. printf("\n(n-k)! = %d", nkFact);
  63. combination = nFact / ( (nkFact) * kFact );
  64. printf("\nNumber of combinations: %d", combination);
  65. printf("\n");
  66. system("PAUSE");
  67. return(0);
  68. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty