Skip to content

Instantly share code, notes, and snippets.

@AlexandruFilipescu
Last active June 9, 2019 16:57
Show Gist options
  • Save AlexandruFilipescu/dd112cb5e23090b615b3f1f956e93904 to your computer and use it in GitHub Desktop.
Save AlexandruFilipescu/dd112cb5e23090b615b3f1f956e93904 to your computer and use it in GitHub Desktop.
C++ Matrice parcursa cu un singur FOR V2(C++ matrix looped with single FOR)
#include <iostream>
using namespace std;
int matrice[50][50],l,c,k,j;
int main() {
cout << "Introduceti numarul de linii: ";
cin >> l;
cout << "\nIntroduceti numarul de coloane: ";
cin >> c;
cout << "\nIntroduceti elementele matricii: ";
for (int i = 0; i < l; i++) {
for (int j = 0; j < c; j++) {
cin >> matrice[i][j];
}
}
for (int i = 0; i < l*c; i++) {
cout << matrice[i/c][i%c] << " ";
if ((i + 1) %c == 0 ) {
cout << endl;
}
}
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment