You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
857 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
#define MAX 101
int D[MAX][MAX];
static int n;
/**
* 功能:读取一个二维数据文件
* 作者:黄海
* 时间2019-11-02
*/
void readTwoDimensionArrayData() {
//数据源文件
string file = "./TwoDimensionArrayDataData.in";
//fstream 流方法读数据
ifstream fin(file);
//读取数塔的层数
fin >> n;
//和cin一样的读取办法
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++)
fin >> D[i][j];
//关闭文件
fin.close();
fin.clear(ios::goodbit);
}
int main() {
//从数据文件中读取数据
readTwoDimensionArrayData();
//输出n
cout << "n=" << n << endl;
//输出二维数组
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
cout << D[i][j] << " ";
}
cout << endl;
}
cout << endl;
}