Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <cs50.h>
- #import <stdio.h>
- #import <string.h>
- #import <stdlib.h>
- int main (void)
- {
- //Getting The Required Information
- long n = get_long ("Total Amount in a Set (n) : ");
- long r = get_long ("Amount in each Sub-Set (r) : ");
- long fac1 = 1;
- long fac2 = 1;
- long fac3 = 1;
- for (int i = 0; i < n; i++)
- {
- fac1 = fac1 * (n-i);
- }
- for (int j = 0; j < (n-r); j++)
- {
- fac2 = fac2 * ((n-r) - j);
- }
- for (int k = 0; k < r; k++)
- {
- fac3 = fac3 * (r-k);
- }
- long permutations = fac1/fac2;
- long combinations = permutations/fac3;
- printf("RESULT\n");
- printf("Permutations = %lo \n", permutations);
- printf("Combinations = %lo \n", combinations);
- }
Advertisement
Add Comment
Please, Sign In to add comment