Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. const int NMAX=50;
  6.  
  7. typedef int matrice[NMAX][NMAX];
  8.  
  9.  
  10.  
  11.  
  12. void leggi_mat(matrice,int &,int &,const char*);
  13.  
  14.  
  15.  
  16. void stampa_mat(matrice,int,int);
  17.  
  18.  
  19.  
  20. int main () {
  21.  
  22. matrice mat;
  23. int rig,col;
  24.  
  25.  
  26.  
  27. leggi_mat(mat,rig,col,"Mat.txt");
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. cout << "M:\n";
  35. stampa_mat(mat,rig,col);
  36.  
  37.  
  38.  
  39. cout << "\n\n";
  40.  
  41. system ("PAUSE");
  42. }
  43.  
  44. void leggi_mat(matrice mat,int &rig,int &col,const char *nomefile){
  45. int i,j;
  46.  
  47. FILE* fp;
  48. fp=fopen(nomefile,"r");
  49.  
  50. if(fp==0){
  51. cout << "Errore nell'apertura del file.";
  52. exit(1);
  53. }
  54.  
  55. fscanf(fp, "%d", &rig);
  56. fscanf(fp, "%d", &col);
  57.  
  58. for(i=0;i<rig;i++)
  59. for(j=0;j<col;j++)
  60.  
  61. fscanf(fp, "%d", &mat[i][j]);
  62. }
  63.  
  64. void stampa_mat(matrice mat,int rig,int col){
  65. int i,j;
  66.  
  67. for(i=0;i<rig;i++){
  68. for(j=0;j<col;j++)
  69. cout <<mat[i][j]<< " ";
  70. cout << "\n";
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement