Chapter 2 Programming II Ppt
Chapter 2 Programming II Ppt
ARRAYS
MOTIVATION
• have 15 numbers to read in from a file and sort into ascending order
Getting-Started-with-Array-Data-Structure.webp
WHAT IS AN ARRAY
• Example
• Input 10 elements
• Display 10 elements
• Sum of 10 input elements
• Average 10 elements
• Sort 10 elements
• Search 1 element from 10 elements
ARRAYS AS PARAMETERS
•
• int data[] = {-2, 45, 0, 11, -9};
{
• }
2.6 MULTIDIMENSIONAL ARRAYS
• int matrix[3][5];
• int matrix [3][5]; is equivalent to int matrix [15]; (3 * 5 = 15)
• pass two dimensional array
• Having the following function prototype:
• void print(int A[][3],int N, int M)
• In order to pass to this function an array declared as:
• int arr[4][3];
• we need to write a call like this:
• print(arr);
2.6 MULTIDIMENSIONAL ARRAYS
• } • }
• }
•