1. Raggaed Array

Creating a pascal triangle using a ragged array, or so i think... Problem is it works great until it prints the triangle out, it prints in the correct format, but the numbers are completely horrible negative numbers.

Code:
```#include <iostream.h>

int **BldCell(int size);
void FillCell(int **cells,int size);
void PrintCell(int **cells,int size);

int main(void)
{
int **cells = 0;
int size = 0;
int row = 0, col = 0;

for (row = 0; row < size; row++)
{
for (col = 0; col < size; col++)
{
cells[row][col] = 0;
}
}

cout << "\nEnter the size of the Pascal Triangle: ";
cin >> size;

cells = BldCell(size);
FillCell(cells,size);
PrintCell(cells,size);

return 0;
}

int **BldCell(int size)
{

int **cells;
int a;

cells = new int * [size];

for (a = 0; a<size; a++)
{
cells[a] = new int [a + 1];
}

return cells;
}

void FillCell (int **cells,int size)
{
int row = 0;
int col = 0;

cells[0][0] = 1;

for (row = 1; row<size; row++)
{
for (col = 0; col<size; col++)
{
if (col == 0)
cells[row][col] = cells[row - 1][0];
else if (col <= row)
cells[row][col] = (cells[row - 1][col - 1] +
cells[row - 1][col]);
else if (col > row)
cells[row][col] = 0;
}
}

return;
}

void PrintCell(int **cells,int size)
{

int row = 0;
int col = 0;

for (row = 0; row<size; row++)
{
for (col = 0; col<=row; col++)
{
cout << cells[row][col];
}
cout << endl;
//delete **cells;
}

return;
}```
Thanx

p.s. msvc++

p.p.s sorry that i didnt put any comments in there

2. fixed it

well thx to those of u who looked at mah post, i figured it out.
thx again

Popular pages Recent additions