fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <limits>
  4. using namespace std;
  5.  
  6. int Pas(int r, int c) {
  7. if (c == 0 || c == r) {
  8. return 1;
  9. } else {
  10. return Pas(r - 1, c - 1) + Pas(r - 1, c);
  11. }
  12. }
  13.  
  14. void PrintPas(int r) {
  15. if (r==1)
  16. cout << Pas(1,0);
  17. else {
  18. PrintPas(r-1);
  19. for (int c=0; c<=r; c++)
  20. cout << Pas(r,c)<< " ";
  21. }
  22. cout <<endl;
  23. }
  24.  
  25. void PrintPas(int r, int c) {
  26. if (r==1)
  27. cout << Pas(1,0)<<" ";
  28. else if (c==-1) {
  29. PrintPas(r-1,r-1);
  30. }
  31. else {
  32. PrintPas(r,c-1);
  33. cout << Pas(r,c)<< " ";
  34. }
  35. if (r==c)
  36. cout <<endl;
  37. }
  38.  
  39. int main(){
  40. //cout << Pas(4,2) << endl;
  41. int n=4;
  42. PrintPas(4,2);
  43.  
  44. // PrintPas(4);
  45.  
  46. /* for (int i=0; i<=n; i++) {
  47.   for (int j=0; j<=i; j++) {
  48.   cout << setw(numeric_limits<int>::digits10+1)<<Pas(i,j);
  49.   }
  50.   cout <<endl;
  51.   }
  52. */
  53. return 0;
  54. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
1  
1 2 1 
1 3 3 1 
1 4 6