SlideShare a Scribd company logo
DISCOVER . LEARN . EMPOWER
2D-Arrays
UNIVERSITY INSTITUTE OF ENGINEERING
DEPARTMENT- ACADEMIC UNITS
FIRST YEAR ENGINEERING PROGRAMMES
Subject Name : Introduction to Problem Solving
Subject Code: 24CSH-101
2
Introduction to
Problem Solving
Course Objectives
The course aims to provide exposure to problem-
solving through programming.
The course aims to raise the programming skills
of students via logic building capability.
With knowledge of C programming language,
students would be able to model real world
problems.
3
CO
Number
Course Outcome
CO1 Remember the concepts related to fundamentals of C language,
draw flowcharts and write algorithm/pseudocode.
CO2 Understand the way of execution and debug programs in C
language.
CO3 Apply various constructs, loops, functions to solve mathematical
and scientific problem.
CO4 Analyze the dynamic behavior of memory by the use of pointers.
CO5 Design and develop modular programs for real world problems
using control structure and selection structure.
Course
Outcomes
4
ASSESSMENT PATTERN
The performance of students is evaluated as follows:
Theory Practical
Components
Continuous Internal
Assessment (CAE)
Semester End
Examination (SEE)
Continuous Internal
Assessment (CAE)
Semester End
Examination (SEE)
Marks 40 60 60 40
Total Marks 100 100
Content
• Two Dimensional Array
• Initialization of Two Dimensional Array
• Memory Representation of 2D Array
• Examples
• References
2-Dimensional
Array
A two-dimensional array is an array where its elements are selected
(identified) using two indices. In 2-D array, to declare and access
elements of a 2-D array we use 2 subscripts instead of 1.
Syntax: data_type array_name[ROW][COL];
The total number of elements in a 2-D array is ROW*COL.
Example: int a[m][n];
In rectangular 2-dimensional arrays, m number of rows and n number of
columns in the array has the same number of array elements.
A conceptual representation of 2D array
Initialization of two-dimensional array: Initialization of 2-D array is
similar to a 1-D array.
Example:
Initialization
2-D Array
After this initialization, each element is as follows:
temp[0][0] : 1
temp[0][1] : 2
temp[0][2] : 3
temp[1][0] : 11
temp[1][1] : 22
temp[1][2] : 33
Memory
Representation
2-D Array
The compiler will allocate the memory for two dimensional array row-
wise meaning the first element of the second row will be placed after the last
element of the first row.
Memory
Representati
on 2-D Array
And if we assume that the first element of the array is at address
1000 and the size of type int is 2 bytes then the elements of the
array will get the following allocated memory locations.
1. Program to store the elements from the user
and store them in an 2D array.
#include<stdio.h>
int main()
{
int disp[2][3], i, j;
for(i=0; i<2; i++)
{
for(j=0;j<3;j++)
{
printf("Enter value for disp[%d][%d]:", i, j);
scanf("%d", &disp[i][j]);
}
}
printf("Two Dimensional array elements:n");
Examples of
2-D Array
for(i=0; i<2; i++)
{
for(j=0;j<3;j++)
{
printf("%d ", disp[i][j]);
if(j==2){ printf("n");
}
}
}
return 0;
}
2.. Program to sum of even and odd of 2D
array.
#include<stdio.h>
int main()
{
int i=0,j=0;
int arr[3][4]={{1,2,3,4},{2,3,4,5},
{3,4,5,6}};
int even=0;int odd=0;
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
if(arr[i][j]%2==0)
{
Examples of
2-D Array
even=even+arr[i][j];
}
else
{
odd=odd+arr[i][j];
}
}
}
printf("Sum of even =%d n",even);
printf("Sum of odd =%d",odd);
return 0; }
SUMMARY
In rectangular 2-dimensional
arrays, m number of rows and n
number of columns in
the array has the same number
of array elements.
The compiler will allocate the
memory for two dimensional
array row-wise meaning the
first element of the second
row will be placed after the
last element of the first row.
2. 3.
1.
In 2-D array, to declare and
access elements of a 2-D array
we use 2 subscripts instead of
1.
FREQUENTLY
ASKED
QUESTIONS
PROGRAMS
1. Write a C Program to addition of two matrices.
2. Write a program in C to calculate determinant of a 3 x 3 matrix.
3. Write a program in C to accept two matrices and check whether
they are equal.
4. Write a C program to transpose of two matrices.
5. Program to multiply two matrices.
UTILISE
YOUR
KNOWLEDGE
TO ANSWER
1.Which of the following is true about arrays in C.
(A) For every type T, there can be an array of T.
(B) For every type T except void and function type, there can be an array of T.
(C) When an array is passed to a function, C compiler creates a copy of array.
(D) 2D arrays are stored in column major form
2. What will be the output of the following C code?
#include <stdio.h>
void f(int a[][3])
{
a[0][1] = 3;
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
printf("%d", a[i][j]);
}
void main()
{
int a[2][3] = {0};
f(a);
}
a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values
Let us see how much you have
learned from the lecture and
how effectively you can apply
your knowledge…!!
UTILISE
YOUR
KNOWLEDGE
TO ANSWER
3. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int a[2][3] = {1, 2, 3, 4, 5};
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
printf("%d", a[i][j]);
}
a) 1 2 3 4 5 0
b) 1 2 3 4 5 junk
c) 1 2 3 4 5 5
d) Run time error
Let us see how much you have
learned from the lecture and
how effectively you can apply
your knowledge…!!
REFERENCES
Book References:
[1] Thareja Reema (2014) Programming in C. 2nd
ed.
[2] Zed A. Shaw, Learn C the Hard Way’
[3] https://en.wikibooks.org/wiki/C_Programming
Vedio Lecture: https://nptel.ac.in/courses/106/105/106105171/
https://nptel.ac.in/courses/106/106/106106127/
https://spoken-tutorial.org/watch/C+and+Cpp/Working+With+2D+Arrays/E
nglish/
Websites: https://beginnersbook.com/2014/01/2d-arrays-in-c-example/
https://processing.org/tutorials/2darray/
https://www.programiz.com/c-programming/c-multi-dimensional-arrays
BOOKS
WEBSITES
COURSES
THANK YOU

More Related Content

PDF
ComputerScience-SQP.pdffhtu h kya hua hai ap ka school
PDF
CS Sample Paper 1
 
PDF
Sample Paper 2 Class XI (Computer Science)
PDF
Programming with c language practical manual
PDF
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
PDF
selfstudys_com_file (4).pdfjsjdcjjsjxjdnxjj
DOC
Sp 1418794917
PDF
Content
ComputerScience-SQP.pdffhtu h kya hua hai ap ka school
CS Sample Paper 1
 
Sample Paper 2 Class XI (Computer Science)
Programming with c language practical manual
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
selfstudys_com_file (4).pdfjsjdcjjsjxjdnxjj
Sp 1418794917
Content

Similar to lecture 2.2.2 2D array.pptx IUGLFHLHFJFY (20)

DOCX
Name _______________________________ Class time __________.docx
PDF
Computer Science Sample Paper 2
 
RTF
CBSE Grade12, Computer Science, Sample Question Paper
PDF
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
PPTX
Arrays 2d Arrays 2d Arrays 2d Arrrays 2d
PPT
the programming Structure of c concept.ppt
DOCX
ExamName___________________________________MULTIPLE CH.docx
PDF
Computer science ms
PPT
Chap-02-1.ppt
PPT
Chap-02-1.ppt
PPTX
C programming-1.pptx
PPT
Chap-02-1.ppt
PPT
Chap-02-1.ppt
PPT
Chap-02-01.ppt
PPT
Chap-02-1.ppt
PPT
Chap 02-1
PDF
Rsa Signature: Behind The Scenes
PDF
Sample Questions for XII Computer Science (2).pdf
PDF
Module wise format oops questions
PDF
CAPE Computer Science Unit 1 Paper 1 - Practice Paper
Name _______________________________ Class time __________.docx
Computer Science Sample Paper 2
 
CBSE Grade12, Computer Science, Sample Question Paper
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
Arrays 2d Arrays 2d Arrays 2d Arrrays 2d
the programming Structure of c concept.ppt
ExamName___________________________________MULTIPLE CH.docx
Computer science ms
Chap-02-1.ppt
Chap-02-1.ppt
C programming-1.pptx
Chap-02-1.ppt
Chap-02-1.ppt
Chap-02-01.ppt
Chap-02-1.ppt
Chap 02-1
Rsa Signature: Behind The Scenes
Sample Questions for XII Computer Science (2).pdf
Module wise format oops questions
CAPE Computer Science Unit 1 Paper 1 - Practice Paper
Ad

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
MYSQL Presentation for SQL database connectivity
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Machine learning based COVID-19 study performance prediction
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Electronic commerce courselecture one. Pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Spectroscopy.pptx food analysis technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Approach and Philosophy of On baking technology
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Unlocking AI with Model Context Protocol (MCP)
Machine learning based COVID-19 study performance prediction
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Chapter 3 Spatial Domain Image Processing.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Spectral efficient network and resource selection model in 5G networks
The Rise and Fall of 3GPP – Time for a Sabbatical?
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
Electronic commerce courselecture one. Pdf
Understanding_Digital_Forensics_Presentation.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Spectroscopy.pptx food analysis technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Ad

lecture 2.2.2 2D array.pptx IUGLFHLHFJFY

  • 1. DISCOVER . LEARN . EMPOWER 2D-Arrays UNIVERSITY INSTITUTE OF ENGINEERING DEPARTMENT- ACADEMIC UNITS FIRST YEAR ENGINEERING PROGRAMMES Subject Name : Introduction to Problem Solving Subject Code: 24CSH-101
  • 2. 2 Introduction to Problem Solving Course Objectives The course aims to provide exposure to problem- solving through programming. The course aims to raise the programming skills of students via logic building capability. With knowledge of C programming language, students would be able to model real world problems.
  • 3. 3 CO Number Course Outcome CO1 Remember the concepts related to fundamentals of C language, draw flowcharts and write algorithm/pseudocode. CO2 Understand the way of execution and debug programs in C language. CO3 Apply various constructs, loops, functions to solve mathematical and scientific problem. CO4 Analyze the dynamic behavior of memory by the use of pointers. CO5 Design and develop modular programs for real world problems using control structure and selection structure. Course Outcomes
  • 4. 4 ASSESSMENT PATTERN The performance of students is evaluated as follows: Theory Practical Components Continuous Internal Assessment (CAE) Semester End Examination (SEE) Continuous Internal Assessment (CAE) Semester End Examination (SEE) Marks 40 60 60 40 Total Marks 100 100
  • 5. Content • Two Dimensional Array • Initialization of Two Dimensional Array • Memory Representation of 2D Array • Examples • References
  • 6. 2-Dimensional Array A two-dimensional array is an array where its elements are selected (identified) using two indices. In 2-D array, to declare and access elements of a 2-D array we use 2 subscripts instead of 1. Syntax: data_type array_name[ROW][COL]; The total number of elements in a 2-D array is ROW*COL. Example: int a[m][n]; In rectangular 2-dimensional arrays, m number of rows and n number of columns in the array has the same number of array elements. A conceptual representation of 2D array
  • 7. Initialization of two-dimensional array: Initialization of 2-D array is similar to a 1-D array. Example: Initialization 2-D Array After this initialization, each element is as follows: temp[0][0] : 1 temp[0][1] : 2 temp[0][2] : 3 temp[1][0] : 11 temp[1][1] : 22 temp[1][2] : 33
  • 8. Memory Representation 2-D Array The compiler will allocate the memory for two dimensional array row- wise meaning the first element of the second row will be placed after the last element of the first row.
  • 9. Memory Representati on 2-D Array And if we assume that the first element of the array is at address 1000 and the size of type int is 2 bytes then the elements of the array will get the following allocated memory locations.
  • 10. 1. Program to store the elements from the user and store them in an 2D array. #include<stdio.h> int main() { int disp[2][3], i, j; for(i=0; i<2; i++) { for(j=0;j<3;j++) { printf("Enter value for disp[%d][%d]:", i, j); scanf("%d", &disp[i][j]); } } printf("Two Dimensional array elements:n"); Examples of 2-D Array for(i=0; i<2; i++) { for(j=0;j<3;j++) { printf("%d ", disp[i][j]); if(j==2){ printf("n"); } } } return 0; }
  • 11. 2.. Program to sum of even and odd of 2D array. #include<stdio.h> int main() { int i=0,j=0; int arr[3][4]={{1,2,3,4},{2,3,4,5}, {3,4,5,6}}; int even=0;int odd=0; for(i=0;i<3;i++) { for(j=0;j<4;j++) { if(arr[i][j]%2==0) { Examples of 2-D Array even=even+arr[i][j]; } else { odd=odd+arr[i][j]; } } } printf("Sum of even =%d n",even); printf("Sum of odd =%d",odd); return 0; }
  • 12. SUMMARY In rectangular 2-dimensional arrays, m number of rows and n number of columns in the array has the same number of array elements. The compiler will allocate the memory for two dimensional array row-wise meaning the first element of the second row will be placed after the last element of the first row. 2. 3. 1. In 2-D array, to declare and access elements of a 2-D array we use 2 subscripts instead of 1.
  • 13. FREQUENTLY ASKED QUESTIONS PROGRAMS 1. Write a C Program to addition of two matrices. 2. Write a program in C to calculate determinant of a 3 x 3 matrix. 3. Write a program in C to accept two matrices and check whether they are equal. 4. Write a C program to transpose of two matrices. 5. Program to multiply two matrices.
  • 14. UTILISE YOUR KNOWLEDGE TO ANSWER 1.Which of the following is true about arrays in C. (A) For every type T, there can be an array of T. (B) For every type T except void and function type, there can be an array of T. (C) When an array is passed to a function, C compiler creates a copy of array. (D) 2D arrays are stored in column major form 2. What will be the output of the following C code? #include <stdio.h> void f(int a[][3]) { a[0][1] = 3; int i = 0, j = 0; for (i = 0; i < 2; i++) for (j = 0; j < 3; j++) printf("%d", a[i][j]); } void main() { int a[2][3] = {0}; f(a); } a) 0 3 0 0 0 0 b) Junk 3 junk junk junk junk c) Compile time error d) All junk values Let us see how much you have learned from the lecture and how effectively you can apply your knowledge…!!
  • 15. UTILISE YOUR KNOWLEDGE TO ANSWER 3. What will be the output of the following C code? #include <stdio.h> void main() { int a[2][3] = {1, 2, 3, 4, 5}; int i = 0, j = 0; for (i = 0; i < 2; i++) for (j = 0; j < 3; j++) printf("%d", a[i][j]); } a) 1 2 3 4 5 0 b) 1 2 3 4 5 junk c) 1 2 3 4 5 5 d) Run time error Let us see how much you have learned from the lecture and how effectively you can apply your knowledge…!!
  • 16. REFERENCES Book References: [1] Thareja Reema (2014) Programming in C. 2nd ed. [2] Zed A. Shaw, Learn C the Hard Way’ [3] https://en.wikibooks.org/wiki/C_Programming Vedio Lecture: https://nptel.ac.in/courses/106/105/106105171/ https://nptel.ac.in/courses/106/106/106106127/ https://spoken-tutorial.org/watch/C+and+Cpp/Working+With+2D+Arrays/E nglish/ Websites: https://beginnersbook.com/2014/01/2d-arrays-in-c-example/ https://processing.org/tutorials/2darray/ https://www.programiz.com/c-programming/c-multi-dimensional-arrays BOOKS WEBSITES COURSES