MULTI-DIMENSIONAL ARRAY

Slides:



Advertisements
Similar presentations
1 ICS103 Programming in C Lecture 16: 2-Dimensional Arrays.
Advertisements

Nested Loops. Problem Print The only printfs you can use are: –printf(“*”); –printf(“\n”); *****
Table of Contents Matrices - Multiplication Assume that matrix A is of order m  n and matrix B is of order p  q. To determine whether or not A can be.
Chapter 8 Multidimensional Arrays C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
A.Abhari CPS1251 Multidimensional Arrays Multidimensional array is the array with two or more dimensions. For example: char box [3] [3] defines a two-dimensional.
Chapter 8 Arrays and Strings
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Course Title Object Oriented Programming with C++ Course instructor ADEEL ANJUM Chapter No: 05 ARRAY 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER) 1.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
1 Topic: Array Topic: Array. 2 Arrays Arrays In this chapter, we will : Learn about arrays Learn about arrays Explore how to declare and manipulate data.
Structured Programming Approach Module VIII - Additional C Data Types Arrays Prof: Muhammed Salman Shamsi.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
For Loop Lecture No 8. Definition In computer science a for loop is a programming language statement which allows code to be repeatedly executed. A for.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Multidimensional Arrays Vectors of Vectors When One Is Not Enough.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
Arrays and Matrices. One-Dimensional Arrays An array is an indexed data structure All variables stored in an array are of the same data type An element.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional Array Explain Arrays.
MAHENDRAN. Session Objectives Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional.
Strings C supports strings using one-dimensional character arrays. A string is defined as a null-terminated character array. In C, a null is 0. You must.
Chapter 2 Array and String. Array Definition of Array : An array is a sequence or collection of the related data items that share a common name. Purpose.
מערכים (arrays) 02 אוקטובר אוקטובר אוקטובר 1602 אוקטובר אוקטובר אוקטובר 1602 אוקטובר אוקטובר אוקטובר 16 Department.
13.4 Product of Two Matrices
(Numerical Arrays of Multiple Dimensions)
Linear Algebra review (optional)
Two-Dimensional Arrays
2-D Array.
Programming application CC213
Multidimensional Arrays
Chapter 8: Arrays Starting Out with C++ Early Objects Ninth Edition
multi-dimensional arrays
Two Dimensional Array Mr. Jacobs.
CHP-2 ARRAYS.
EKT120 : Computer Programming
Dynamic Array Multidimensional Array Matric Operation with Array
EGR 115 Introduction to Computing for Engineers
Array 9/8/2018.
Lecture 7 – Arrays (1) PGT 106 : C PROGRAMMING.
Module 2 Arrays and strings – example programs.
ARRAYS An array is a sequence of data item of homogeneous value(same type). Arrays are of two types: 1. One-dimensional arrays 2. Multi-Dimensional arrays.
Computer Graphics Matrix
Two Dimensional Arrays
Pointers and Arrays S.Bhuvaneshwari Assistant Professor/CSE
Engineering Problem Solving with C++, Etter/Ingber
Lecture 10 Arrays.
EKT150 : Computer Programming
1020: Introduction to Programming Mohamed Shehata November 7, 2016
Review of Arrays and Pointers
EKT120: Computer Programming
Multidimensional Arrays
Arrays Chapter 8 Copyright © 2008 W. W. Norton & Company.
Chapter 2 Array and String Visit to more Learning Resources.
UNIT - 3 Noornilo Nafees.
Multidimensional array
Multidimensional Arrays
Dr Tripty Singh Arrays.
Lets Play with arrays Singh Tripty
Multi-Dimensional Arrays
Introduction to Matlab
Linear Algebra review (optional)
C++ Array 1.
Arrays and Matrices Prof. Abdul Hameed.
ICS103: Programming in C Searching, Sorting, 2D Arrays
Visit for more Learning Resources
Presentation transcript:

MULTI-DIMENSIONAL ARRAY Guided To Laxmikant Sahu Guided By Mr. Jeetendra Kumar Sir

Multi-Dimensional Arrays Multidimensional arrays are derived from the basic or built-in data types of the C language. Two-dimensional arrays are understood as rows and columns with applications including two-dimensional tables, parallel vectors, and two-dimensional matrices. Mostly Two-dimensional array are used in Multi-dimensional array.

Arrays of Greater Dimension One-dimensional arrays are linear containers. [0] [1] [2] Multi-dimensional Arrays [2] [0] [1] [2] [3] [1] [0] [0] [0] [1] [1] [2] [2] [3] Two-Dimensional [0] [1] [2] [3] [4] Three-dimensional

TWO DIMENSIONAL ARRAY

CONTENT Introduction to two dimensional array Declaration Initialization Input and output of a 2d array Storage allocation

Two - Dimensional Arrays What is a Two-dimensional array? B = Array type Array name Array dimension = 2 51, 52, 53 54, 55, 56 Row 1 Int b[2][3] = {(51, 52, 53),(54, 55, 56)}; Row 2 First row second row Two rows Col 1 Col 2 Col 3 Three columns Algebraic notation C notation

Indexes in 2D arrays Assume that the two dimensional array called val is declared and looks like the following: To access the cell containing 6, we reference val[1][3], that is, row 1, column 3. val Col 0 Col 1 Col 2 Col 3 Row 0 8 16 9 52 Row 1 3 15 27 6 Row 2 14 25 2 10

DECLARATION How to declare a multidimensional array? int b[2][3]; the name of the array to be b the type of the array elements to be int the dimension to be 2 (two pairs of brackets []) the number of elements or size to be 2*3 = 6

Declaration Statement

INITIALIZATION How to initialize a Two-Dimensional array? Initialized directly in the declaration statement int b[2][3] = {51, 52, 53, 54, 55, 56}; b[0][0] = 51 b[0][1] = 52 b[0][2] = 53 Use braces to separate rows in 2-D arrays. int c[4][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}; int c[ ][3] = {{1, 2, 3}, Implicitly declares the number of rows to be 4.

Input of Two-Dimensional Arrays Data may be input into two-dimensional arrays using nested for loops interactively or with data files. A nested for loop is used to input elemts in a two dimensional array. In this way by increasing the index value of the array the elements can be entered in a 2d array.

Output of Two-Dimensional Arrays The output of two-dimensional arrays should be in the form of rows and columns for readability. Nested for loops are used to print the rows and columns in row and column order. By increasing the index value of the array the elements stored at that index value are printed on the output screen.

A program to input elements in a two dimensional array and print it. #include<stdio.h> #include<conio.h> void main() { int a[3][3]; int i,j; clrscr(); printf(“enter the elements in the array:”);

for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) scanf(“%d”,&a[i][j]); } printf(“%d”,a[i][j]); } printf(“\n”); getch();

OUTPUT :- Enter elements in array: 1 2 3 4 5 6 7 8 9 123 456 789

Storage Allocation In storage allocation of array contagious memory is allocated to all the array elements.

EXAMPLES BASED ON TWO-DIMENSIONAL ARRAY

A program to add two matrix entered by the user and print it. #include<stdio.h> #include<conio.h> void main() { int a[3][3],b[3][3],c[3][3]; int i,j; clrscr(); printf(“enter the elements in both the array:”);

for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) scanf(“%d”,&a[i][j]); } scanf(“%d”,&b[i][j]);

for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) c[i][j]=a[i][j]+b[i][j]; printf(“%d”,c[i][j]); } printf(“\n”); getch();

OUTPUT:- Enter elements in array:- 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 2 4 6 9 81012 1 141618 2

A program to input a matrix and print its transpose. #include<stdio.h> #include<conio.h> void main() { int a[3][3],b[3][3]; int i,j; clrscr(); printf(“enter the elements in the array”);

for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) scanf(“%d”,&a[i][j]); } for(j=0 ; i<3 ; i++) for(i=0 ; j<3 ; j++) printf(“%2d”,&b[j][i]); getch();

OUTPUT:- Enter elements in array: 1 2 3 4 5 6 7 8 9 147 258 369

A program to multiply two matrix entered by the user and print it. #include<stdio.h> #include<conio.h> void main() { int a[3][3],b[3][3]; int i,j; clrscr(); printf(“enter the elements in the array”);

for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) scanf(“%d”,&a[i][j]); } scanf(“%d”,&b[i][j]);

for(i=0 ; i<3 ; i++) { for(j=0 ; j<3 ; j++) c[i][j]=0; for(k=0 ; k<2 ; k++) c[i][j]=c[i][j]+a[i][k]*b[k][j] printf(“%3d”,c[i][j]); } printf(“\n”); getch();

OUTPUT:- Enter elements in array:- 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 30 66 102 9 36 81 121 1 42 96 150 2

THANK YOU