C++编程题,VC++6.0,如图
3个回答
推荐于2016-08-29
展开全部
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int n;
cout << "输入n的大小(n>=0):" << endl;
cin >> n;
ofstream ofs("result.txt");
if (!ofs)
{
cout << "can not open result.txt for write!" << endl;
return 0;
}
int *data = new int[n + 1];
data[0] = 1;
int pre;
for (int i = 0; i <= n; ++i)
{
if (i == 0)
{
ofs << data[0] << endl;
continue;
}
pre = 1;
int j = 1;
for (; j < i; ++j)
{
int tmp = data[j];
data[j] = data[j] + pre;
pre = tmp;
}
data[j] = 1;
for (j = 0; j <= i; ++j)
ofs << data[j] << " ";
ofs << endl;
}
delete []data;
ofs.close();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询