0

Does it work properly ?? Or what should i do??

I make a multidimensional array and want to get inputs from user for each part.. Here's my code int a,b; cin>>a>>b; int c[a][b]; for(int i=0,j=0; i<a,j<b; i++,j++){ cin>>c[i][j]; cout<<c[i][j]; } And here i want to print each part of array... did i go wrong? For example the user has entered the inputs like this a=2 b=3 ===> {{1,2,3},{5,8,0}} now I expect the output to print 1 2 3 5 8 0

16th Jan 2021, 6:28 AM
Ali_combination
Ali_combination - avatar
6 odpowiedzi
16th Jan 2021, 8:39 AM
Ipang
+ 1
Ipang thank you so much♡
16th Jan 2021, 8:50 AM
Ali_combination
Ali_combination - avatar
+ 1
int a[x][y] where <x> and <y> are defined at runtime is called VLA (Variable Length Array), it is not part of C++ standards, and thus may/may not be supported widely. I would rather suggest you not to use them for the mentioned reason, more details follows 👇 https://en.m.wikipedia.org/wiki/Variable-length_array https://stackoverflow.com/questions/1887097/why-arent-variable-length-arrays-part-of-the-c-standard
16th Jan 2021, 8:57 AM
Ipang
+ 1
Ali_combination It's a pleasure bro 👌
16th Jan 2021, 8:59 AM
Ipang
0
Thanks fellas ! But I got it solved like this : int x,y; cin>>x>>y; int a[x][y]; double t=0; string e[x]={"First boy","Second boy",...} ;//any number of boys u need for(int p=0; p<a; p++){ for(int q=0; q<b; q++){ cin>>a[p][q]; } } for(int i=0; i<x; i++){ cout<<endl<<e[i]<<":"<<endl; for(int j=0; j<y; j++){ cout<<"Object "<<j+1<<":"<<a[i][j]<<endl; t=t+a[i][j]; } cout<<endl<<"average is:"<<t/y; } in fact it's like that im calculating average of each student's grades.
16th Jan 2021, 8:48 AM
Ali_combination
Ali_combination - avatar
0
Pąľľąvī thanks alot
16th Jan 2021, 8:50 AM
Ali_combination
Ali_combination - avatar