Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include "funzioni.h"
- int leggiMatrice (matrice m, int&r, int&c)
- {
- fstream f0;
- r=0; c=0;
- f0.open("file iniziale.txt", ios::in);
- f0>>r; cout<<"la matrice ha "<<r<<" righe\n";
- f0>>c; cout<<"la matrice ha "<<c<<" colonne\n";
- for (int i=0; i<r;i++)
- {
- cout<<"\n";
- for (int j=0;j<c;j++)
- {
- f0>>m[i][j];
- cout<<"["<<m[i][j]<<"] ";
- }
- }
- f0.close();
- }
- int MAX (matrice m, int r, int c, int&max_i, int&max, int&max_j)
- {
- max=0;
- max_i=0;
- max_j=0;
- for (int i=0; i<r;i++)
- {
- for (int j=0;j<c;j++)
- {
- if (m[i][j]>max)
- {
- max=m[i][j];
- max_i=i;
- max_j=j;
- }
- }
- }
- cout<<"\n\nil massimo si trova nella riga numero "<<max_i<<" e nella colonna numero "<<max_j<<"\n\n";
- }
- int eliminaRiga (matrice m, int r, int c, int& max_i)
- {
- int i, j;
- if(max_i==r-1)
- {
- r--;
- }
- else
- {
- for(i=0;i<r;i++)
- {
- for(j=0;j<c-1;j++)
- {
- if(i>=max_i)
- {
- m[i][j]=m[i+1][j];
- }
- }
- }
- }
- }
- int eliminaColonna (matrice m, int r, int c, int& max_j)
- {
- int i,j;
- if(max_j==c-1)
- {
- c--;
- }
- else
- {
- for(i=0;i<r;i++)
- {
- for (j=0;j<c-1;j++)
- {
- if (j>=max_j)
- {
- m[i][j]=m[i][j+1];
- }
- }
- }
- }
- }
- int nuovaMatrice (matrice m, int r, int c)
- {
- fstream f1;
- int i, j;
- f1.open("f_output.txt", ios::out);
- for (i=0;i<r;i++)
- {
- f1<<"\n";
- cout<<"\n";
- for (j=0;j<c;j++)
- {
- f1<<"["<<m[i][j]<<"] ";
- cout<<"["<<m[i][j]<<"] ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement