Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- const int NMAX=50;
- typedef int matrice[NMAX][NMAX];
- void leggi_mat(matrice,int &,int &,const char*);
- void stampa_mat(matrice,int,int);
- int main () {
- matrice mat;
- int rig,col;
- leggi_mat(mat,rig,col,"Mat.txt");
- cout << "M:\n";
- stampa_mat(mat,rig,col);
- cout << "\n\n";
- system ("PAUSE");
- }
- void leggi_mat(matrice mat,int &rig,int &col,const char *nomefile){
- int i,j;
- FILE* fp;
- fp=fopen(nomefile,"r");
- if(fp==0){
- cout << "Errore nell'apertura del file.";
- exit(1);
- }
- fscanf(fp, "%d", &rig);
- fscanf(fp, "%d", &col);
- for(i=0;i<rig;i++)
- for(j=0;j<col;j++)
- fscanf(fp, "%d", &mat[i][j]);
- }
- void stampa_mat(matrice mat,int rig,int col){
- int i,j;
- for(i=0;i<rig;i++){
- for(j=0;j<col;j++)
- cout <<mat[i][j]<< " ";
- cout << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement