C++ 杨辉三角,没有使用数组


C++ 杨辉三角,没有使用数组

  1. #include <iostream>   
  2. #include <iomanip>   
  3. #include <stdlib.h>   
  4.   
  5. using namespace std;  
  6.   
  7. int main()  
  8. {  
  9.     int m, n, c = 1;  
  10.     cout << "\n";  
  11.     for (m = 1; m <=13; m++) {  
  12.         cout<<setw(40-3*m)<<c;  
  13.         for (n = 1; n<=m; n++) {  
  14.             c = c*(m-n+1)/n;  
  15.             cout<<setw(6)<<c;  
  16.         }  
  17.         cout << "\n";  
  18.     }  
  19.     system("pause");  
  20.     return 0;  
  21. }  

相关内容