0

Hello guys need help on what wrong in my coding..

#include<iostream> using namespace std; int main() { int m,n; int a[size][size]; cout<<”enter the number of rows”<<endl; cin>>m; cout<<”enter the number of columns”<<endl; cin>>n; cout<<”enter the elements in table”<<endl; for(int i = 0; i<m; i++) { for(int j = 0; j<n; j++) { cin>>a[i][j]; } } //output each array element’s value for(int i = 0; i<m; i++) for(int j = 0; j<n; j++) { cout<<”a[“<<i<<”][“<<j<<”]”; cout>>a[i][j]<<endl; } return 0; }

6th Jan 2022, 7:50 AM
Rodelyn Ungsod
Rodelyn Ungsod - avatar
5 Answers
+ 1
*ineteger array a is wrongly declared, declare it after taking m and n Declare is as int a[m][n]; *in sololearn playground, your double quotes are suspicious, * while printing elements of the array, use insertion operator << with cout. Correct version is attached... https://code.sololearn.com/cz2XAaxV4dEf/?ref=app
6th Jan 2022, 8:02 AM
saurabh
saurabh - avatar
+ 1
you are using the wrong quotes, use "" instead of ””. a[size] [size] size is not defined, replace with m n a[m] [n] last cout line cout << not cout >>.
6th Jan 2022, 8:02 AM
Bahha┣
Bahha┣ - avatar
+ 1
Just a friendly reminder that VLAs are illegal in C++ Maybe C++23 (with mdarrays) will finally give us a really nice way to do it But until then... I guess you could use vector<vector<int>>
6th Jan 2022, 11:50 AM
Angelo
Angelo - avatar
0
“ ” to " use half angle input method int a[m][n]; array size cout>>a[i][j]<<endl; cout<< all in the error prompt Input all data at once separated by Enter in the code playground #include<iostream> using namespace std; int main() { int m,n; cout<<"enter the number of rows"<<endl; cin>>m; cout<<"enter the number of columns"<<endl; cin>>n; int a[m][n]; cout<<"enter the elements in table"<<endl; for(int i = 0; i<m; i++) { for(int j = 0; j<n; j++) { cin>>a[i][j]; } } //output each array element’s value for(int i = 0; i<m; i++) for(int j = 0; j<n; j++) { cout<<"a["<<i<<"]["<<j<<"]"; cout<<a[i][j]<<endl; } return 0; }
6th Jan 2022, 8:04 AM
FanYu
FanYu - avatar
0
Thanks for quickly response 😊
6th Jan 2022, 8:07 AM
Rodelyn Ungsod
Rodelyn Ungsod - avatar