DityaSen

Permutation and Combinations

Mar 9th, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | Source Code | 0 0
  1. #import <cs50.h>
  2. #import <stdio.h>
  3. #import <string.h>
  4. #import <stdlib.h>
  5.  
  6. int main (void)
  7. {
  8.     //Getting The Required Information
  9.     long n = get_long ("Total Amount in a Set (n) : ");
  10.     long r = get_long ("Amount in each Sub-Set (r) : ");
  11.  
  12.  
  13.     long fac1 = 1;
  14.     long fac2 = 1;
  15.     long fac3 = 1;
  16.  
  17.     for (int i = 0; i < n; i++)
  18.     {
  19.         fac1 = fac1 * (n-i);
  20.     }
  21.  
  22.     for (int j = 0; j < (n-r); j++)
  23.     {
  24.         fac2 = fac2 * ((n-r) - j);
  25.     }
  26.  
  27.     for (int k = 0; k < r; k++)
  28.     {
  29.         fac3 = fac3 * (r-k);
  30.     }
  31.  
  32.  
  33.     long permutations = fac1/fac2;
  34.     long combinations = permutations/fac3;
  35.  
  36.     printf("RESULT\n");
  37.     printf("Permutations = %lo \n", permutations);
  38.     printf("Combinations = %lo \n", combinations);
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment