that_one_nigga_you_k

triangulo de pascal funcionando

Jun 12th, 2023
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. long fact(long n){
  7.  
  8.     long h = 1;
  9.  
  10.     if(n == 1 || n==0){
  11.         return(1);
  12.     }
  13.  
  14.     else{
  15.    
  16.         for(int i = 1; i <= n; ++i) {
  17.             h *= i;
  18.         }
  19.  
  20.         return(h);
  21.     }
  22. }
  23.  
  24.    
  25.  
  26.  
  27. long comb (int g, int e){
  28.     int r;
  29.  
  30.     if(e>g) cout<<"deu merda";
  31.  
  32.     r=fact(g)/(fact(e)*fact(g-e));
  33.  
  34.     return(r);
  35. }
  36.  
  37. void gerar(int t){
  38.  
  39.     for(int i = 1; i <= t; ++i) {
  40.         for(int j = 0; j <= i; ++j) {
  41.             cout << comb(i, j)<<"\t";
  42.         }
  43.         cout << "\n";
  44.  
  45. }
  46. }
  47.  
  48. int main(){
  49.  
  50.     int l,h,t;
  51.  
  52.     gerar(6);
  53.    
  54.     return(0);
  55. }
Add Comment
Please, Sign In to add comment