9 views

Uploaded by CHANDRA BHUSHAN

Array

- Math Mode
- Bgm111 API Rm
- Mathematics in Structural Engineering, Course, Dr.colin Caprani
- Unit 8 c Variables
- Error Codes
- Java
- Julia Cheatsheet
- Modeling System Influence with MATLAB
- cpp-mdl1_001
- G2_Lab7_Dec13
- SystemManual_rev0
- 74781953-WHAT-TO-STUDY-STPM-MATHEMATICS-T-S-PAPER-1.pdf
- 19640287
- c Intrview Quest
- Steganography Java
- 160
- Class
- Introductory API for Matlab
- 2nd Term Project
- NyarBoard Documentation

You are on page 1of 7

2D array

1-D ARRAY

DEFINITION

ROW MAJOR

IMPLEME NTATION

ADDRESS CALCULATION

COLUMN MAJOR

Definition 2 D Array : A 2D array is an array in which each element is itself an Array. For instance , an array A[M][N] is an M X N matrix. Where : M = No. of rows N = No. of Columns M X N = No. of elements. Implementation of 2-D Array : There are two way to store elements of 2-D array in Memory .

1. Row Major - Where elements are stored row wise. 2. Column Major. Where elements are stored Column wise. Finding The Location(address) of an element in 2-D array : CASE : 1 . When elements are stored row wise : Case 1.1 When lower bond is not given. A[M][N] or A[M,N] Address of A[I][J] or A[I,J] = B+ W[N( I)+J] . M= Total No of Rows N= Total No of Columns I = Expected row J = Expected Column W = size of each element in byte. Case 1.2 When lower bound is given. A[LrUr][LcUc] or A[Lr : Ur , Lc : Uc] Address of A[I][J] or A[I,J] = B+ W[N( I - Lr )+(J-L c )] .

Page 2 of 7 N= Uc Lc + 1 (Total No of Columns ) I = Expected row J = Expected Column W = size of each element in byte. Lr = Lower Bound of row Lc= Lower Bound of column Uc = Upper Bound of column

CASE : 2 . When elements are stored column wise: Case 2.1 When lower bond is not given. A[M][N] or A[M,N] Address of A[I][J] or A[I,J] = B+ W[M(J)+I] . M= Total No of Rows N= Total No of Columns I = Expected row J = Expected Column W = size of each element in byte. Case 2.2 When lower bound is given. A[LrUr][LcUc] or A[Lr : Ur , Lc : Uc] Address of A[I][J] or A[I,J] = B+ W[( I - Lr )+M(J-Lc )] . M= Uc Lc + 1 (Total No of row) I = Expected row J = Expected Column W = size of each element in byte. Lr = Lower Bound of row Lc = Lower Bound of column Uc = Upper Bound of column Basic Arithmetic Operation On 2 D Array. -Addition -Subtraction -Multiplication Addition OR Subtraction of two 2D Array : Addition of two 2D array can be performed when they are equal in size. Function to find sum of two matrix: A[m1][n1] , B[m2][n2] void summatrix(int a[][],int m1, int n1, int b[][], int m2,int n2) { int c[m1][n1]; if (m1==m2 && n1==n2) { for(int I=0;I<m1;I++) { for(int j=0;j<n1;j++)

cout<<Matrix can not be added; return; } //resultant Matrix for(int I=0;I<m1;I++) { for(int j=0;j<n1;j++) { cout<<c[I][J]; } cout<<endl; }

Multiplication of two 2-D array : Necessary condition : no. of columns of first matrix must be equal to no of rows Of second matrix. A[m1][n1] , B[m2][n2] n1 = m2 Void productmatrix(int a[][],int m1, int n1, int b[][], int m2,int n2) {int sum ; int c[m1][n2] ; if (n1==m2 ) { for(int I=0;I<m1;I++) { for(int j=0;j<n2;j++) { c[I][J]=0; for(int k=0;k<n1;k++) { c[I][J]=a[I][K]*b[K][J]+c[I][J]; } } } } else { cout<<Matrix can not be multiplied ;

Page 4 of 7 return; } //resultant Matrix for(int I=0;I<m1;I++) { for(int j=0;j<n2;j++) { cout<<c[I][J]; } cout<<endl; } Transpose of matrix : Interchanges of rows and columns of matrix . void transposematrix(int a[][],int m, int n) { int tp[m][n]; for(int I=0;I<m;I++) { for(int j=0;j<n;j++) { tp[I][J]=a[J][I]; } } //resultant Matrix for(int I=0;I<n;I++) { for(int j=0;j<m;j++) { cout<<c[I][J]; } cout<<endl; } }

Problems On 2-D array : Problem 1 : Write a function in C++ which accept an integer array and its size as arguments and assign the elements into a two dimentional array of integer in the following format : If the array is 1,2,3,4,5,6 The resultant 2D array is Given below : 1 1 1 1 1 1 2 2 2 2 2 0 3 3 3 3 0 0 4 4 4 0 0 0 5 5 0 0 0 0 6 0 0 0 0 0

Page 5 of 7

Sol: void func(int a[] , int size) { int a2[size][size]; int I,j; for(I=0;I<size;I++) { for( j=0;j<size;j++) { if((I+j)>=size) { a2[I][j]=0; } else { a2[I][j]=a[j]; } cout<<a2[I][j]<< ; } cout<<endl; } } Numerical Problems : Problem1: Calculate the address of the element a[3][5] of 2-D array a[7][20] stored in column wise matrix assume that the base address is 2000, each element required 2 bytes of storage. [Ans.2076] marks 2 Formula used : A[M][N] or A[M,N] Address of A[I][J] or A[I,J] = B+ W[M(J)+I] . M= Total No of Rows = 7 N= Total No of Columns=20 I = Expected row =3 J = Expected Column =5 W = size of each element in byte.=2

Problem2: Calculate the address of the element a[2][4] of 2-D array a[5][5] stored in row wise matrix assume that the base address is 1000, each element required 4 bytes of storage. [Ans.1056] marks 2 Formula used : A[M][N] or A[M,N] Address of A[I][J] or A[I,J] = B+ W[N(I)+J] . M= Total No of Rows = 5

Page 6 of 7 N= Total No of Columns=5 I = Expected row =2 J = Expected Column =4 W = size of each element in byte.=4

Address of A[2][4]= 1000+4(5*2+4) = 1056. Problem3: Each element of an array Data[1..10][110] required 8 byte of storage. If base address of array Data is 2000 determine the location of Data[4][5]. When the array is stored (i) row wise (ii) column wise. Ans .(i) 2272 (ii) 2344 Marks-4 Formula used : (i) row wise A[LrUr][LcUc] or A[Lr : Ur , Lc : Uc] Address of A[I][J] or A[I,J] = B+ W[N( I - Lr )+(J-L c )] . N= Uc Lc + 1 (Total No of Columns ) =10-1+1=10 I = Expected row =4 J = Expected Column=5 W = size of each element in byte.=8 Lr = Lower Bound of row=1 Lc= Lower Bound of column=1 Uc = Upper Bound of column=10 Address of A[4][5] or A[4,5] = 2000+ 8[10( 4 - 1 )+(5-1 )] . = 2272. (II) column wise A[LrUr][LcUc] or A[Lr : Ur , Lc : Uc] Address of A[I][J] or A[I,J] = B+ W[( I - Lr )+M(J-Lc )] . M= Uc Lc + 1 (Total No of row) = 10-1+1=10 I = Expected row =4 J = Expected Column=5 W = size of each element in byte.=8 Lr = Lower Bound of row=1 Lc = Lower Bound of column=1 Uc = Upper Bound of column=10 Address of A[4][5] or A[4,5] = 2000+ 8[( 4 - 1 )+10(5-1 )] .=2344 Problem 4 : If an array B[11][8] is stored is column wise and B[2][2] is stored at and B[3][3] is stored at 1084 then find the address of B[5][3]. Ans. 1094 Marks - 4 A[M][N] or A[M,N] Address of A[I][J] or A[I,J] = B+ W[M(J)+I] . M= Total No of Rows N= Total No of Columns I = Expected row J = Expected Column 1024

Page 7 of 7 W = size of each element in byte. Address of B[2][2]= B+ W[11*2+2]=1024 B+24W=1024 ---- equation1 Address of B[3][3]= B+ W[11*3+3]=1084 B+ 36W=1084 equation ---- 2 Solving above these two equation to obtain base address and size of a element . W=5 , B=904 Address of B[5][3]= 904+ 5[11*3+5]=1094

- Math ModeUploaded byPetra Rozehnalová
- Bgm111 API RmUploaded bymateiuli
- Mathematics in Structural Engineering, Course, Dr.colin CapraniUploaded bymexces
- Unit 8 c VariablesUploaded byapi-3842522
- Error CodesUploaded byमौसम Magyar
- JavaUploaded bymuhzinamoideen
- Julia CheatsheetUploaded bymbrijbhushan4863
- Modeling System Influence with MATLABUploaded byDerek
- cpp-mdl1_001Uploaded byNikhil S Pillai
- G2_Lab7_Dec13Uploaded byMuhammad Ahsan Razaq
- SystemManual_rev0Uploaded bylocalon
- 74781953-WHAT-TO-STUDY-STPM-MATHEMATICS-T-S-PAPER-1.pdfUploaded byGEG Kulim
- 19640287Uploaded byAshiqueHussain
- c Intrview QuestUploaded bygullu1001
- Steganography JavaUploaded byRishi Anand Pandey
- 160Uploaded byOmid Toussi
- ClassUploaded bykhaliltmanelkh
- Introductory API for MatlabUploaded byRaymond Wong
- 2nd Term ProjectUploaded bydevildarsh
- NyarBoard DocumentationUploaded byxavikchorro
- Maths Basic 2Uploaded byPushpesh Ranjan
- 7Uploaded byBeauponte Pouky Mezonlin
- 2.SequenceUploaded bylalteja
- Long (Java 2 Platform SE v1.4.2)Uploaded bylevypa
- upload_test_4.pdfUploaded byKaran
- A Collision Free Control for Tight Formation of Multi-MissilesUploaded byivy_publisher
- arrays.pptxUploaded byKarthik Pallavali
- Aplicatia 1 Cu TemporizatoareUploaded byfcompart
- Terms & Conditions 2016 18Uploaded byRaj Munda
- Maths Schemes F4Uploaded byWan Nur Aida Akhmal

- Customer-Bankers Relationship - Gr8AmbitionZUploaded byJanibasha Shaik
- Screen ShortUploaded byCHANDRA BHUSHAN
- ERD Assignment HindiUploaded byCHANDRA BHUSHAN
- 143960524-resumeUploaded byCHANDRA BHUSHAN
- General Awareness Updates – January 2013.pdfUploaded byCHANDRA BHUSHAN
- Resume Format for Bank Jobs PDFUploaded byCHANDRA BHUSHAN
- Scope of Work_1Uploaded byCHANDRA BHUSHAN
- C++Uploaded byCHANDRA BHUSHAN
- 05-Adaptive Resonance TheoryUploaded byCHANDRA BHUSHAN
- 06-Fuzzy Set TheoryUploaded byCHANDRA BHUSHAN
- 08-Fundamentals of Genetic AlgorithmsUploaded byCHANDRA BHUSHAN
- Notes on Operations ResearchUploaded byCHANDRA BHUSHAN
- Context Free LangaugesUploaded byCHANDRA BHUSHAN
- English Grammar Shortcut Rules.pdfUploaded byNiranjan Sharma
- Advt_01_2013Uploaded byCHANDRA BHUSHAN
- 4050_Design_Pattern.pptUploaded byCHANDRA BHUSHAN
- ADTs.pptUploaded byCHANDRA BHUSHAN
- Binary Search TreesUploaded bymani271092
- 1_principles.pdfUploaded byCHANDRA BHUSHAN
- 02javascript.pptUploaded byCHANDRA BHUSHAN
- DEF.pdfUploaded byCHANDRA BHUSHAN
- ABC.pdfUploaded byCHANDRA BHUSHAN
- 4 Models 4upUploaded byCHANDRA BHUSHAN
- C++ Program Collection by M.Irfan Arshad(GCUF)Uploaded byirfan_chand_mian
- Static NoteUploaded byCHANDRA BHUSHAN
- Exception NotesUploaded byCHANDRA BHUSHAN
- Abstract NoteUploaded byCHANDRA BHUSHAN
- Project SynopsisUploaded byCHANDRA BHUSHAN
- hciUploaded byCHANDRA BHUSHAN
- PrologUploaded byCHANDRA BHUSHAN

- Math 3031 Syllabus and HWUploaded byDaniel Lee Eisenberg Jacobs
- Fundamentals of TimeUploaded bywithravi
- InstallationUploaded bymeraat
- art-3A10.1186-2Fs40327-015-0024-4Uploaded byaisyah sri lestari
- DIP.pdfUploaded byravindrapadsala
- Chapter 8.docxUploaded byNina Ad
- Competency Based Performance AppraisalUploaded byAnna Hudson
- ProbStat HandoutUploaded byDC Arkin
- Utility TurbinesUploaded byPremkumar Vasudevan
- um3750Uploaded bySofiane Melki
- (API 610-10th) Centrifugal Pump - SI Units.xlsUploaded byf09ai
- Alexander CrockettUploaded byapi-26556803
- Hazop ManualUploaded bylearningtoflyy
- Comparison of R22 and R134aUploaded byMuhammad Bilal Farooq
- Einhell Catalogue RED PowerTools 2014 GB Screen 05Uploaded byZarQuiquiriqui
- Chilled Water Balancing for HVAC System Method StatementUploaded byamg007
- Air Preparation Equimaents FilUploaded byloveselvan43
- Challenges of Employee Retention.pdfUploaded bytalalarayaratamara
- Biology Form 4,Chapter 3(movement across the plasma membrane)Uploaded bySatpal Singh
- pneumatic System ComponentUploaded bybhadresh
- PID ModellingUploaded byOwais
- Nanni 6.420 TDi Marine Diesel 6cylUploaded byAlbertoJim90
- ReferencesUploaded byHarman124
- 1971----Seismic Resistance of Prestressed Concrete Beam-Column AssembliesUploaded byshuangyaksa
- 741opAmpUploaded byOrlando Fernandez
- hetar obtl.pdfUploaded byJason Montesa
- 09.1 Shared PreferencesUploaded byFu'adika Nur Maulana
- High Speed Dispersion of Titanium Dioxide Chemical Industry 130707221258 Phpapp02Uploaded bychevypickup
- ERC411_C4_BIUploaded byEsther Ponmalar Charles
- r8200Uploaded byShameen McJester Dahalan