Why we use 2d arrays

Question is why we use  2D Arrays.

Farz karta ha ka agr hum na 1 class ka 10  students ka data  store karna ha . To ya to Hum easily kr la .

Just 
int arr[10];
 To is tarha hum 10 students ka naam ya number , Jo be store kr sakta ha . 

Lakin agr 5 classes  ka 10 10 students ka data store karna ho to ??

Is ka lya Hama 5 arrays banani para gi .
Is case ma hum 2D array use kra ga . Just Simple 1 array sa 5 classes ka students ka data store .

int b[5][10];






TO hum aise banye ga array

int b[5][10]
for(int i=0;i<5;i++)
for(int j=0;i<10;j++)
{
cin >> b[i][j];
}
}


Sbb sa pehla i ki value 0 ho gi to wo class 1 ko represent kra ga , phir 2nd loop chala gi our us ma class 1 ka 10 students ka data store ho gye ga .Because wo 10 dfa chalaa gi . 
b[0][0]    1st class 1st student
                                b[0][1]    1st class 2st student                                 
b[0][2] 1st class 3rd student
....
..
b[0][9] 1st class 10th student
10 dfa chalna ka bad i ki value 1 ho gye gi i=1;
our 2nd class ka data store ho gye ga , 10 students ka 

b[1][0] 2nd  class 1st student
b[1][1] 2nd class 2st student
b[1][2] ......................
..
..
..
isi tarha 1st loop 5 dfa chala gi our nested loop harr dfa 10 dfa chala gi . 
1st loop yaha Class ko represent kr rhi ha our inner loop students ko .
Thats why we use 2D ARRAYS.

LET AGR 3D ARRAY USE KARNI ho to usa kasa kra ga .
5 schools ki 5 classes ka 10 students ka data store karna ho to ?
just 
b[5][5][10];
isi tarha pehla 5 school ko represent kra ga , dosra 5 classes ko our tesra 10 students ko .

Agr is ma koi ghalti ha to zarror bataye 
Comment & Share
Join fb group 


Comments