Advertisement
FelipeNeto2

COMBINAÇÃO SIMPLES

May 29th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. int fatorial(int n){
  3.     int fat = 1, v[n], i;
  4.    
  5.     v[0]=1;
  6.    
  7.     for(i=1; i<n; i++){
  8.         v[i]=v[i-1]+1;
  9.     }
  10.  
  11.     for(i=1; i<n; i++){
  12.         fat*=v[i];
  13.     }
  14.    
  15.     return fat;
  16. }
  17.  
  18.  
  19. int main(){
  20.     int n, p, nume, deno1, deno2, comb;
  21.    
  22.     printf("Digite n: ");
  23.     scanf("%d", &n);
  24.    
  25.     printf("Digite p: ");
  26.     scanf("%d", &p);
  27.    
  28.     nume=fatorial(n);
  29.    
  30.     deno1=fatorial(n-p);  
  31.    
  32.     deno2=fatorial(p);
  33.    
  34.     comb=nume/(deno1*deno2);
  35.    
  36.     printf("\nCombinacao de %d escolhe %d = %d", n, p, comb);
  37.    
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement