2D array

 

Matrix definition

 

// This is called 2metrix in programing world

//calculating memory consumption rule is:- (rows*columns)*datatypesize = total memory consumption;
      _      _
eg: | 2    6|
      |5     5|   =>  (rows*columns)*datatypesize  => (2*2)*4 => 16 bytes is memory consumption
      -        - 
 1D array deceleration is:- int[] number = new int[size];
2D array  deceleration is:- int[][] number = new int[rows][columns];
 
 eg: //Example of 2darray and calculating sum
 int a[][], i, j,sum=0;
printf("Enetr element of matrix:  :");
 
for(i=0;i<2;i++){
for(j=0; j<3;j++){
sacnf("%d", &a[i][j]);
}
}
 
printf("Martix is\n");
for(i=0;i<2;i++){
for(j=0; j<3;j++){
printf("%d\t",  a[i][j]);
sum = sum + a[i][j];
}
printf("\n");
printf("\n Sum = %d",sum);
}
 
 //transpose of matrix
 
 

Comments

Popular posts from this blog

CyberSecurity

VERTICAL SCALING 💋

prisma using in project idx 13.3