// Chuong2_bai14.cpp : Defines the entry point for the console application.
/*
Write a program : Input: an interger n, output: n rows of PasCal Triangel
Example:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
*/
#include "stdafx.h"
#include "conio.h"
#include "iostream"
usingnamespace std;
class Pascal_Triangel
{
private:
int** mang;
int n;
public:
~Pascal_Triangel()
{
delete[] mang;
delete mang;
}
Pascal_Triangel(int n)
{
mang = newint* [n];
for(int i=0;i<n;i++)
{
mang[i] = newint [n];
}
//Khoi tao tam giac
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(j>i)
mang[i][j]=0;
elseif(j==0 || i==j)
mang[i][j]=1;
else
mang[i][j]=mang[i-1][j-1]+mang[i-1][j];
}
}
Pascal_Triangel()
{
cout<<"Nhap kich thuoc cua mang:";
cin>>n;
mang = newint* [n];
for(int i=0;i<n;i++)
{
mang[i] = newint [n];
}
//Khoi tao tam giac
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(j>i)
mang[i][j]=0;
elseif(i==0 || i==j)
mang[i][j]=1;
else
mang[i][j]=mang[i-1][j-1]+mang[i-1][j];
}
}
void Show()
{
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(mang[i][j]==0)
{
if(j==n-1)
cout<<"\n";
continue;
}
else
cout<<mang[i][j]<<" ";
}
}
};
int _tmain(int argc, _TCHAR* argv[])
{
int n;
cout<<"Nhap so dong cua tam giac Pascal can hien thi:";cin>>n;
Pascal_Triangel P(n);
P.Show();
return 0;
}
And this is a bug:
Debug Assesion failed!
Program: ...al Studio 2010/Projects/Chuong2_bai14/Debug/Chuong2_bai14.exe
File: f:\dd\vstools\crt_bld\self_x86\crt\src\dbgdel.cpp
Line:52
Expression:_BLOCK_TYPE_IS_VALID (pHead->nBlockUse)
Thanks for help