杨辉三角形问题
#include <iostream.h>class yanghui{
int *y[10];
public:
yanghui()
{int i,j;
for(i=0; i<10; i++)
{y[i] = new int[sizeof(int) * (i+1)];
for(j=0; j<=i; j++)
{if(j=0 || i==j)
*(y[i]+j)=1;
else
*(y[i]+j) = *(y[i-1]+(j-1)) + *(y[i-1]+j);
}
}
void showyanghui()
{int i,j;
for(i=0; i<10; i++)
{for(j=0; j<=i; j++)
{cout << *(y[i]+j);}
cout << endl;}
}
};
main()
{yanghui a;
a.showyanghui();
}
我自己看了一下没发现什么问题。出现错误提示:
yanghui.cpp
C:\yanghui.cpp(27) : warning C4183: 'main': member function definition looks like a ctor, but name does not match enclosing class
C:\yanghui.cpp(28) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.