SlideShare a Scribd company logo
Two dimensional
- Two dimensional arrays are declared
similarly to one dimensional arrays:
char t[20][10]; (and referred to as a
matrix, or as a "table")
The first subscript gives the row number, and
the second subscript specifies column number.
We can also initialize a two-dimensional array
in a declaration statement; E.g.,
int m[2][3] = {{1, 2, 3}, {4, 5, 6}};
which specifies the elements in each row of the
array (the interior braces around each row of
values could be omitted). The matrix for this
example is






=
654
321
m
Specification of the number of rows could be
omitted. But other subscript specifications can
not be omitted. So, we could also write the
initialization as
int m[ ][3] = {{1, 2, 3}, {4, 5, 6}};
int a[2][3]= {1,2,3,4,5,6};
specifies 6 integer locations.
Storage for array elements are in contiguous locations in
memory in row major order (unlike column major order in
Fortran), referenced by subscripts(or index) values starting at 0
for both rows and columns.
a[0][0] a[0][1] a[0][2] a[1][0] a[1][1] a[1][2]
RAM
1 2 3 4 5 6
1. Problem Definition
Assume we have a file “in.dat” (located in the pwd) consisting
of 10 rows of 10 integers per row (100 integers total). Write a
C program which reads from the file and stores the numbers
in a two dimensional array named ‘mat’, computes the largest
of all of these numbers and prints the largest value to the
screen.
 
2. Refine, Generalize, Decompose the problem definition
(i.e., identify sub-problems, I/O, etc.)
Input = from file “in.dat”
Output= Largest of the 100 integers printed to screen.
3. Develop Algorithm
Use Unix redirection to read file “in.dat”.
Use nested for loop to go through two dimensional array to
#include <stdio.h>
void main(void)
{
int row, col, maximum;
/* Declare a 2-D array called ‘mat’ which can hold a 10-by-10 */
/* matrix of integers */
int mat[10][10];
/* Write code here to read from the file ‘in.dat’ */
for(row=0;row<10;++row)
for(col=0;col<10;++col)
scanf("%i",&mat[row][col]);
/* Write code to find the largest value in the array ‘mat’ */
maximum = mat[0][0]; /* why ??? */
for(row=0;row<10;++row) /* How does this work??? */
for(col=0;col<10;++col)
if (mat[row][col] > maximum)
maximum = mat[row][col];
/* Print the largest value to the screen */
printf(" max value in the array = %in",maximum);
}
The typedef mechanism in C allows us to define our own
data types. For example,
typedef double matrix[10][20];
In this example we create a new data-type named matrix.
We can declare a variable of data-type matrix by
matrix a;
and this declaration is equivalent to
double a[10][20];
Other examples of the use of typedef are,
typedef int blah; /* don’t do this !!!!! */
typedef char string[5];
In the first example we give another name or alias to the
data type int .
In the second example we create a new data-type named
string.
To declare a variable of data-type blah ,
blah x;
this declaration is equivalent to
int x;
To declare a variable of data-type string ,
string var ="init"; /* declare and initialize */
scanf("%s",var); /* read in a string of chars */
strcpy(var , "next");
The declaration
string morse[26];
declares morse as an array of 26 elements. Each element has
data-type string.
The declaration and initialization:
string morse[26] =
{".-", "-...", "-.-.", "-..", ".", "..-.",
"--.", "....", "..", ".---", "-.-", ".-..",
"--", "-.", "---", ".--.", "--.-", ".-.", "...",
"-", "..-", "...-", ".--", "-..-", "-.--", "--.. " };
declares morse as an array of 26 elements with
morse[0] = ".-"
morse[1] = "-..." and so on...
Standard (ANSI) C allows up to 12 dimension.
But more computation is required by the system
to locate elements in multi-subscripted arrays.
Therefore, in problems involving intensive
numerical calculations, we should use arrays
with fewer dimension.
We can also use 3, 4, … dimensional arrays,
e.g.,
threeDArray [i][j][k];
Ad

More Related Content

What's hot (20)

Arrays in c
Arrays in cArrays in c
Arrays in c
vampugani
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
Awais Alam
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
janani thirupathi
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
Neeru Mittal
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
2D Array
2D Array 2D Array
2D Array
Ehatsham Riaz
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
Mazharul Islam
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
أحمد محمد
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Rokonuzzaman Rony
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
Self-Employed
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
NUPOORAWSARMOL
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma
 
C string
C stringC string
C string
University of Potsdam
 
Arrays in c
Arrays in cArrays in c
Arrays in c
CHANDAN KUMAR
 
Array
ArrayArray
Array
Anil Neupane
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
Omprakash Chauhan
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
Neeru Mittal
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
Mazharul Islam
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
Self-Employed
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
NUPOORAWSARMOL
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
Omprakash Chauhan
 

Viewers also liked (20)

2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
Education Front
 
Arrays
ArraysArrays
Arrays
archikabhatia
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
Array in C
Array in CArray in C
Array in C
Kamal Acharya
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
Gagan Deep
 
Array in c language
Array in c languageArray in c language
Array in c language
home
 
05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
Kelly Swanson
 
Enter The Matrix
Enter The MatrixEnter The Matrix
Enter The Matrix
Mike Anderson
 
C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]
MomenMostafa
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
Princess Sam
 
2D Array
2D Array2D Array
2D Array
Swarup Boro
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
 
Presentation on Logical Operators
Presentation on Logical OperatorsPresentation on Logical Operators
Presentation on Logical Operators
Sanjeev Budha
 
Application of Matrices
Application of MatricesApplication of Matrices
Application of Matrices
Mohammed Limdiwala
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
Neveen Reda
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
eShikshak
 
Applications of matrices in real life
Applications of matrices in real lifeApplications of matrices in real life
Applications of matrices in real life
SuhaibFaiz
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
Abhishek Pachisia
 
Coordinate systems
Coordinate systemsCoordinate systems
Coordinate systems
Saad Raja
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
Gagan Deep
 
Array in c language
Array in c languageArray in c language
Array in c language
home
 
C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]
MomenMostafa
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
Princess Sam
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
 
Presentation on Logical Operators
Presentation on Logical OperatorsPresentation on Logical Operators
Presentation on Logical Operators
Sanjeev Budha
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
Neveen Reda
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
eShikshak
 
Applications of matrices in real life
Applications of matrices in real lifeApplications of matrices in real life
Applications of matrices in real life
SuhaibFaiz
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
Abhishek Pachisia
 
Coordinate systems
Coordinate systemsCoordinate systems
Coordinate systems
Saad Raja
 
Ad

Similar to Two dimensional array (20)

Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 
Unit 2
Unit 2Unit 2
Unit 2
TPLatchoumi
 
ARRAYS
ARRAYSARRAYS
ARRAYS
muniryaseen
 
Array in C
Array in CArray in C
Array in C
adityas29
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
Anurag University Hyderabad
 
Arrays
ArraysArrays
Arrays
Chukka Nikhil Chakravarthy
 
3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
FolkAdonis
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
Thesis Scientist Private Limited
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
Array &strings
Array &stringsArray &strings
Array &strings
UMA PARAMESWARI
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
Dr.Subha Krishna
 
6.array
6.array6.array
6.array
Shankar Gangaju
 
PPS 4.4ARRAYS ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...
PPS 4.4ARRAYS  ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...PPS 4.4ARRAYS  ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...
PPS 4.4ARRAYS ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...
Sitamarhi Institute of Technology
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
Array
ArrayArray
Array
Shankar Gangaju
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
nmahi96
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
Mohamed Abdallah
 
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docxArraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
pranauvsps
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
Tareq Hasan
 
Ad

More from Rajendran (20)

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
Rajendran
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
Rajendran
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
Rajendran
 
Red black tree
Red black treeRed black tree
Red black tree
Rajendran
 
Hash table
Hash tableHash table
Hash table
Rajendran
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
Rajendran
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
Rajendran
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
Rajendran
 
Master method
Master method Master method
Master method
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Hash tables
Hash tablesHash tables
Hash tables
Rajendran
 
Lower bound
Lower boundLower bound
Lower bound
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
Rajendran
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
Rajendran
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
Rajendran
 
Np completeness
Np completenessNp completeness
Np completeness
Rajendran
 
computer languages
computer languagescomputer languages
computer languages
Rajendran
 
Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
Rajendran
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
Rajendran
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
Rajendran
 
Red black tree
Red black treeRed black tree
Red black tree
Rajendran
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
Rajendran
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
Rajendran
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
Rajendran
 
Master method
Master method Master method
Master method
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
Rajendran
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
Rajendran
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
Rajendran
 
Np completeness
Np completenessNp completeness
Np completeness
Rajendran
 
computer languages
computer languagescomputer languages
computer languages
Rajendran
 

Recently uploaded (20)

LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 

Two dimensional array

  • 2. - Two dimensional arrays are declared similarly to one dimensional arrays: char t[20][10]; (and referred to as a matrix, or as a "table") The first subscript gives the row number, and the second subscript specifies column number.
  • 3. We can also initialize a two-dimensional array in a declaration statement; E.g., int m[2][3] = {{1, 2, 3}, {4, 5, 6}}; which specifies the elements in each row of the array (the interior braces around each row of values could be omitted). The matrix for this example is       = 654 321 m
  • 4. Specification of the number of rows could be omitted. But other subscript specifications can not be omitted. So, we could also write the initialization as int m[ ][3] = {{1, 2, 3}, {4, 5, 6}};
  • 5. int a[2][3]= {1,2,3,4,5,6}; specifies 6 integer locations. Storage for array elements are in contiguous locations in memory in row major order (unlike column major order in Fortran), referenced by subscripts(or index) values starting at 0 for both rows and columns. a[0][0] a[0][1] a[0][2] a[1][0] a[1][1] a[1][2] RAM 1 2 3 4 5 6
  • 6. 1. Problem Definition Assume we have a file “in.dat” (located in the pwd) consisting of 10 rows of 10 integers per row (100 integers total). Write a C program which reads from the file and stores the numbers in a two dimensional array named ‘mat’, computes the largest of all of these numbers and prints the largest value to the screen.   2. Refine, Generalize, Decompose the problem definition (i.e., identify sub-problems, I/O, etc.) Input = from file “in.dat” Output= Largest of the 100 integers printed to screen. 3. Develop Algorithm Use Unix redirection to read file “in.dat”. Use nested for loop to go through two dimensional array to
  • 7. #include <stdio.h> void main(void) { int row, col, maximum; /* Declare a 2-D array called ‘mat’ which can hold a 10-by-10 */ /* matrix of integers */ int mat[10][10]; /* Write code here to read from the file ‘in.dat’ */ for(row=0;row<10;++row) for(col=0;col<10;++col) scanf("%i",&mat[row][col]); /* Write code to find the largest value in the array ‘mat’ */ maximum = mat[0][0]; /* why ??? */ for(row=0;row<10;++row) /* How does this work??? */ for(col=0;col<10;++col) if (mat[row][col] > maximum) maximum = mat[row][col]; /* Print the largest value to the screen */ printf(" max value in the array = %in",maximum); }
  • 8. The typedef mechanism in C allows us to define our own data types. For example, typedef double matrix[10][20]; In this example we create a new data-type named matrix. We can declare a variable of data-type matrix by matrix a; and this declaration is equivalent to double a[10][20];
  • 9. Other examples of the use of typedef are, typedef int blah; /* don’t do this !!!!! */ typedef char string[5]; In the first example we give another name or alias to the data type int . In the second example we create a new data-type named string.
  • 10. To declare a variable of data-type blah , blah x; this declaration is equivalent to int x; To declare a variable of data-type string , string var ="init"; /* declare and initialize */ scanf("%s",var); /* read in a string of chars */ strcpy(var , "next"); The declaration string morse[26]; declares morse as an array of 26 elements. Each element has data-type string.
  • 11. The declaration and initialization: string morse[26] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.. " }; declares morse as an array of 26 elements with morse[0] = ".-" morse[1] = "-..." and so on...
  • 12. Standard (ANSI) C allows up to 12 dimension. But more computation is required by the system to locate elements in multi-subscripted arrays. Therefore, in problems involving intensive numerical calculations, we should use arrays with fewer dimension. We can also use 3, 4, … dimensional arrays, e.g., threeDArray [i][j][k];
  翻译: