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
7 Respuestas
+ 1
Using new operator to create a 2D array
https://stackoverflow.com/questions/936687/how-do-i-declare-a-2d-array-in-c-using-new
+ 1
Ipang thank you so much♡
+ 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
+ 1
Ali_combination
It's a pleasure bro 👌
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.
0
Pąľľąvī thanks alot