Advertisement
Guest User

Matrici C++

a guest
Feb 23rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void insMatrice(int m[][10], int righe, int colonne) {
  5.    
  6.     int i=0, j;
  7.    
  8.     for (i=0; i<righe; i++) {
  9.         for (j=0; j<colonne; j++) {
  10.             cout << "M[" << i << "][" << j << "] = ";
  11.             cin >> m[i][j];
  12.         }
  13.     }
  14.  
  15. }
  16.  
  17. int main(int argc, char **argv)
  18. {
  19.     int m[10][10];
  20.     int righe=0, colonne=0;
  21.    
  22.     do {
  23.         cout << "Righe = ";
  24.         cin >> righe;
  25.         if ( (righe<1)||(righe>10) ) {
  26.             cout << "Errore, riprova!" << endl;
  27.         }
  28.     }while( (righe<1)||(righe>10) );
  29.    
  30.     do {
  31.         cout << "Colonne = ";
  32.         cin >> colonne;
  33.         if ( (colonne<1)||(colonne>10) ) {
  34.             cout << "Errore, riprova!" << endl;
  35.         }
  36.     }while( (colonne<1)||(colonne>10) );
  37.    
  38.     cout << endl;
  39.     insMatrice(m, righe, colonne);
  40.    
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement