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; }
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
+ 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 >>.
+ 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>>
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;
}
0
Thanks for quickly response đ