2016-11-21 103 views
-1

我正在嘗試做一個pascal三角形,但由於某種原因,我有錯誤「運行時檢查失敗#2 - 圍繞變量堆棧'TP'被破壞了。「有人能幫助我嗎?運行時檢查失敗#2 - 圍繞變量'TP'的堆棧已損壞

#include <iostream> 
using namespace std; 

void main() 
{ 
int TP[100][100] = { 0 }, n; 
do 
{ 
    cout << "Digite a ordem do triangulo de pascal: "; 
    cin >> n; 
} while (n < 0 || n > 100); 
for (int j = 0; j < n; j++) 
{ 
    TP[j][0] = 1; 
    TP[j][j] = 1; 
} 
for (int i = 2; i < n + 1; i++) 
    for (int j = 1; TP[i][j] != 1; j++) 
     TP[i][j] = TP[i - 1][j - 1] + TP[i - 1][j]; 
for (int i = 0; i < n; i++) 
{ 
    cout << endl; 
    for (int j = 0; j != i + 1; j++) 
     cout << TP[i][j] << " "; 
} 
cout << endl << endl; 
system("pause"); 
} 

回答

0

你超越數組邊界在for (int i = 2; i < n + 1; i++)i == nn=100

+0

我沒有看到,非常感謝你 –

相關問題