Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <fstream>
- #define INP "input.INP"
- using namespace std;
- int **input1(int &n)
- {
- int **G;
- ifstream inp(INP);
- if (inp == NULL)
- {
- cout<<"Khong thay file input";
- return NULL;
- }
- inp >> n ;
- G = new int *[n];
- for (int i=0; i<n; i++)
- {
- G[i] = new int [n];
- for (int j=0; j<n; j++)
- inp >> G[i][j];
- }
- return G;
- }
- void input2(int ***G, int &n)
- {
- ifstream inp(INP);
- if (inp == NULL)
- {
- cout<<"Khong thay file input";
- return;
- }
- inp >> n ;
- *G = new int *[n];
- for (int i=0; i<n; i++)
- {
- (*G)[i] = new int [n];
- for (int j=0; j<n; j++)
- inp >> (*G)[i][j];
- }
- }
- void input3(int **(&G), int &n)
- {
- ifstream inp(INP);
- if (inp == NULL)
- {
- cout<<"Khong thay file input";
- return;
- }
- inp >> n ;
- G = new int *[n];
- for (int i=0; i<n; i++)
- {
- G[i] = new int [n];
- for (int j=0; j<n; j++)
- inp >> G[i][j];
- }
- }
- void output(int **G, int n)
- {
- for (int i=0; i<n; i++)
- {
- cout<<endl;
- for (int j=0; j<n; j++)
- cout<<setw(2)<<G[i][j];
- }
- }
- int main()
- {
- int **G, n;
- input3(G,n);
- output(G,n);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement