+ 1
I could not understand what i have done ..i need some guidence...
#include <iostream> using namespace std; int main() { int count = 0; int x[2][3]={{2,3,4},{8,9,6}}; for(int i=0,j=2;i+j>=-30;i++,j=j-3){ cout<<x[i][j]<<endl; count++; } cout<<"\n\nNumber of 4:"<<count; return 0; } before using loop i did this cout << x[0][2] << endl; cout << x[1][-1] << endl; cout << x[2][-4] << endl; cout << x[3][-7] << endl; cout << x[4][-10] << endl; cout << x[5][-13] << endl;
5 Respuestas
+ 4
Whenever you want to understand, you print what you don't understand out.
In your case, you need to do this:
cout<<"i: "<<i<<", j: "<<j<<endl;
https://code.sololearn.com/c29rkGtIeMU8/?ref=app
Is the mist cleared now?
+ 1
More clearly like this...........but i am still confused.....
#include <iostream>
using namespace std;
int main()
{
int count = 0;
int x[2][3]={{2,3,4},{8,9,6}};
for(int i=0,j=2;i+j>=-30;i++,j=j-3){
cout << "x[" << i << "][" << j << "]: ";
cout << x[i][j]<< endl;
count++;
}
cout<<"\n\nNumber of 4:"<<count;
return 0;
}
+ 1
Good that you altered the cout to makes thing even clearer.
Can you tell me, for the six numbers stored in x, how do you address these six numbers?
+ 1
Sir what i actually need to get guidance is about how the result i.e 4 is coming....
+ 1
Yes and I am trying to tell you why the result is always 4
Now, in your x, it is two by three, can you try to test in your code :
x[0]
x[1]
x[0][0]
x[0][1]
and so on
What do you find out?