Advertisement
AlexandruFilipescu

Matrice parcursa cu un singur FOR V2(Matrix with single FOR)

May 19th, 2019
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int matrice[50][50],l,c,k,j;
  4.  
  5.  
  6.  
  7.  
  8. int main() {
  9.  
  10.     cout << "Introduceti numarul de linii: ";
  11.     cin >> l;
  12.     cout << "\nIntroduceti numarul de coloane: ";
  13.     cin >> c;
  14.     cout << "\nIntroduceti elementele matricii: ";
  15.  
  16.     for (int i = 0; i < l; i++) {
  17.         for (int j = 0; j < c; j++) {
  18.             cin >> matrice[i][j];
  19.         }
  20.     }
  21.  
  22.  
  23.     for (int i = 0; i < l*c; i++) {
  24.         cout << matrice[i/c][i%c] << " ";
  25.         if ((i + 1) %c == 0 ) {
  26.             cout << endl;
  27.         }
  28.     }
  29.  
  30.  
  31.  
  32.  
  33.     system("pause");
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement