Advertisement
Guest User

Untitled

a guest
May 26th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1.  
  2.  
  3. #include<iostream>
  4.  
  5. using namespace std;
  6.  
  7. int TinhGiaiThua(int n)
  8. {
  9.     int f;
  10.     for (f = 1; n > 1; n--)
  11.     {
  12.         f *= n;
  13.     }
  14.     return f;
  15. }
  16.  
  17. int TinhSoPascal(int a, int b)
  18. {
  19.     int z = 0;
  20.     z = TinhGiaiThua(a) / (TinhGiaiThua(b) * TinhGiaiThua(a - b));
  21.     return z;
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27.     int n;
  28.     cin >> n;
  29.     for (int i = 0; i <n; i++)
  30.     {
  31.         for (int j = 0; j < (n - 1) - i; j++)
  32.         {
  33.             cout << " ";
  34.         }
  35.         for (int j = 0; j <= i; j++)
  36.         {
  37.             cout << TinhSoPascal(i, j) << " ";
  38.         }
  39.         cout << endl;
  40.     }
  41.  
  42.  
  43.     system("pause");
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement