Advertisement
nguyenvanquan7826

Nhap mang 2 chieu bang ham

Apr 9th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <fstream>
  5. #define INP "input.INP"
  6. using namespace std;
  7.  
  8. int **input1(int &n)
  9. {
  10.     int **G;
  11.     ifstream inp(INP);
  12.     if (inp == NULL)
  13.     {
  14.         cout<<"Khong thay file input";
  15.         return NULL;
  16.     }
  17.     inp >> n ;
  18.     G = new int *[n];
  19.     for (int i=0; i<n; i++)
  20.     {
  21.         G[i] = new int [n];
  22.         for (int j=0; j<n; j++)
  23.             inp >> G[i][j];
  24.     }
  25.     return G;
  26. }
  27.  
  28. void input2(int ***G, int &n)
  29. {
  30.     ifstream inp(INP);
  31.     if (inp == NULL)
  32.     {
  33.         cout<<"Khong thay file input";
  34.         return;
  35.     }
  36.     inp >> n ;
  37.     *G = new int *[n];
  38.     for (int i=0; i<n; i++)
  39.     {
  40.         (*G)[i] = new int [n];
  41.         for (int j=0; j<n; j++)
  42.             inp >> (*G)[i][j];
  43.     }
  44. }
  45.  
  46. void input3(int **(&G), int &n)
  47. {
  48.     ifstream inp(INP);
  49.     if (inp == NULL)
  50.     {
  51.         cout<<"Khong thay file input";
  52.         return;
  53.     }
  54.     inp >> n ;
  55.     G = new int *[n];
  56.     for (int i=0; i<n; i++)
  57.     {
  58.         G[i] = new int [n];
  59.         for (int j=0; j<n; j++)
  60.             inp >> G[i][j];
  61.     }
  62. }
  63.  
  64. void output(int **G, int n)
  65. {
  66.     for (int i=0; i<n; i++)
  67.     {
  68.         cout<<endl;
  69.         for (int j=0; j<n; j++)
  70.             cout<<setw(2)<<G[i][j];
  71.     }
  72. }
  73.  
  74. int main()
  75. {
  76.     int **G, n;
  77.     input3(G,n);
  78.     output(G,n);
  79.    
  80.     system("pause");
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement