Two Dimensional Array - PTInstitute


Presentation Description

Hi everyone, here we are presenting a presentation about 2-dimensional array. An array of arrays is known as a 2-dimensional array. The two-dimensional array in programming is also known as the matrix. A matrix can be represented as a table of rows and columns. We demonstrate how to store the elements entered by the user in a 2d array and how to display the elements of a two-dimensional array. The individual elements of the above array can be accessed by using two subscript instead of one. The first subscript denotes row number and second denotes column number. As we can see in the above image both rows and columns are indexed from 0. So the first element of this array is at a[0][0] and the last element is at a[1][2]. At Embedded training institute, teach 2-dimensional array very clear step by steps. Read More:


Presentation Transcript

slide 1:

TWO DIMENSIONAL ARRAY By Professional Training Institute Professional Embedded Training Institute in Bangalore

slide 2:

TWO DIMENSIONAL ARRAY We have introduced array as if we want to save a hundred values then its difficult to declare variables so we used array .now if we want hundred such arrays then we can have two-dimensional arrays .so an array of arrays is known as 2d array. Through our website you can learn more.

slide 3:

1.1 PROGRAM TO CHECK WHETHER THE TWO33 MATRICES ARE EQUAL OR NOT First we taken the two33 matrixes afterwards we need to check that all elements inside the two matrices are equal or not in both matrices with respect to position wise also if all elements with respect to position in two matrices are equal then prints both matrices are EQUAL otherwise prints both matrixes are not equal. DESCRIPTION

slide 4:

10 mins includestdio.h int main int matrix133matrix233ijcount0 printf“enter the elements of first 33 matrix\n” fori0i3i++ //rows forj0j3j++// columns scanf“d” matrix1ij //input from the user printf“enter the elements of second 33 matrix\n” fori0i3i++ forj0j3j++ scanf“d” matrix2ij fori0i3i++ //loop for checking whether two matrixes are equal or not forj0j3j++ ifmatrix1ijmatrix2ij count++// increment the count value if the elements are not equal ifcount0 printf“2 matrixes are equal\n” else printf“2 matrixes are not equal\n” 15 mins

slide 5:

1.2 TO PERFORM SCALAR MULTIPLICATION OF33 MATRIX Here we can multiply any constant element with the 33 matrixor any other matrix.first user ask the input for matrix along with the constant variable. DESCRIPTION

slide 6:

10 mins includestdio.h//preprocessor directive with header file int main int matrix1010ijnconstantrowcolmatrix110 10 printf“enter the number of rows of the array elements\n” scanf“d” row printf“enter the number of columns of the array elements\n” scanf“d” col printf“enter the matrix elements\n” fori0irowi++ //for row elements forj0jcolj++ //for column elements scanf“d” matrixij printf“enter the constant element to multiplied with the matrix\n” scanf“d” constant fori0irowi++ //loop for multiplying a constant with the given matrix forj0jcolj++ matrix1ijconstantmatrixij printf“the new matrix is\n” fori0irowi++ //loop for printing the multiplied matrix 15 mins

slide 7:

10 mins forj0jcolj++ printf” d” matrix1ij printf“\n” //end of main function 15 mins

slide 8:

1.3 TO FIND THE SUM OF EACH ROW AND COLUMN OF A 33 MATRIX First We have to take33 matrixthen we need to find the sum of each elements of the row1afterwards sum of each elements of row2 and then row3 similar method is needed to find the sum of each elements of columns also afterwards print all the sums individually. DESCRIPTION

slide 9:

10 mins includestdio.h int main int matrix33ijsumrow0sum1 printf“enter the elements of the matrix33\n” fori0i3i++// scanning for rows forj0j3j++// scanning for columns scanf“d” matrixij fori0i3i++//loop for finding the sum of each rows and columns sum0 sum10 forj0j3j++ sumsum+matrixij//sum is sum of each rows sum1sum1+matrixji//sum1 is sum of each columns printf“sum of rowdd\n” rowsum//printing sum of each rows value printf“sum of columndd\n” rowsum1//printing sum of each column value row++ 15 mins

slide 10:

1.4 MULTIPLICATION OF TWO 33 MATRIX First we take the two 33 matrixesor any afterwards we need to check the rows of the first matrix is equal to the columns of the second matrix if it is satisfied then only you to process for further steps otherwise print no multiplication is possibleif it is satisfied then only multiply 2 matrix. DESCRIPTION

slide 11:

10 mins includestdio.h int main int matrix133matrix233matrix333 row1col1row2col2ijkmul printf“enter the number of rows of the first matrix\n” scanf“d” row1 printf“enter the columns of the first matrix\n” scanf“d” col1 printf“enter the elements of the first matrix\n” fori0irow1i++ forj0jcol1j++ scanf“d” matrix1ij printf“enter the number of rows of second matrix\n” scanf“d” row2 printf“enter the number of columns of second matrix\n” scanf“d” col2 ifrow1col2 //if rows of the 1st matrix not equal to second matrix exit program otherwise continue printf“multiplication not possible\n” else 15 mins

slide 12:

10 mins printf“enter the elements of the second matrix\n” fori0irow2i++ forj0jcol2j++ scanf“d” matrix2ij printf“multiplication of two matrix is\n” fori0irow1i++ // matrix multiplication takes place forj0jcol2j++ mul0 fork0kcol1k++ mulmul+matrix1ikmatrix2kj printf” d” mul printf“\n” 15 mins

slide 13:

1.5 PROGRAM TO STORE 10 NAME INTO 2D ARRAY AND PRINT THEM We declare a 2 dimensional character array of required sizeafterwards we need to store names and print them. DESCRIPTION

slide 14:

10 mins includestdio.h int main char names2020 int rowcolij printf“enter the rows and columns of the 2d array\n” scanf“d d” rowcol printf“enter the names you want to print\n” fori0irowi++ scanf“s” namesi0//user input to store names fori0irowi++ printf“s\n” namesi0//printing the names 15 mins

slide 15:

1.6 PROGRAM TO SWAP THE TWO ARRAYS To swap two strings in c programming we want to ask user to enter two strings and then make a temporary variable of same type and then place elements of string 1 in temp and and elements of string 2 in 1 and then temp in string 2. DESCRIPTION

slide 16:

10 mins includestdio.h int main char array110array210temp10”\0″ int len10len20ij printf“enter the elements of the first array\n” scanf“s” array1 printf“enter the elements of the second array\n” scanf“s” array2 whilearray1len1’\0′//loop for calculating the length of the first array len1++ printf“the length of the first array is d\n” len1 whilearray2len2’\0′//loop for calculating the length of the second array len2++ printf“the length of the second array is d\n” len2 fori0ilen1i++//using temporary variable we swap the 2 given arrays and print after the swapping process tempiarray1i 15 mins

slide 17:

10 mins fori0ilen2i++ array1iarray2i fori0ilen1i++ array2itempi fori0ilen2i++ printf“c” array1i printf“\n” forj0jlen1j++ printf“c” array2j 15 mins

slide 18:

1.7 PROGRAM TO CHECK WHETHER THE GIVEN STRING IS PALINDROME OR NOT A string is palindrome if the reverse of that string is equal to original string.firstly we need to declare a character array of some size after we need to obtain input string from the user and take another array and copy the reversing order of first string and compare the both strings if it is equal print as the given string is palindrome else print the given string is not an palindrome. DESCRIPTION

slide 19:

10 mins includestdio.h includestring.h int main char str10rev10”\0″ int length0ij printf“enter the string\n” scanf“s” str whilestrlength’\0′ length++ printf“length of the string isd\n” length forilength-1j0i0jlengthi–j++/ for loop for reversing a original string and store it inanother character array/ revistrj fori0ilengthi++//comparing original string with the reversing string ifrevistri j1 else j0 ifj1 printf“palindrome\n” else printf“not an palindrome\n” 15 mins

slide 20:

1.8 PROGRAM TO INTERCHANGING THE DIAGONALS OF MATRIX Firstly we take the matrix only square matrixafterwards we need to interchange the left diagonal elements towards right and vice-versa and print the result of interchanging the diagonal elements. DESCRIPTION

slide 21:

10 mins includestdio.h int main int a1010rowcolumnijtemp printf“enter the number of rows and columns of the matrix\n” scanf“d d” rowcolumn printf“enter the elements of the matrix\n” fori0irowi++ forj0jcolumnj++ scanf“d” aij fori0irowi++ tempaii aiiairow-i-1 airow-i-1temp fori0irowi++ forj0jcolumnj++ printf” d” aij printf“\n” 15 mins

slide 22:

1.9 WRITE A PROGRAM TO PRINT UPPER TRIANGULAR MATRIX We have to take one square matrix and print the upper triangular matrix only remaining the term should be zero or empty. DESCRIPTION

slide 23:

10 mins includestdio.h int main int matrix33rowcolumn printf“enter the 33 matrix elements\n” forrow0row3row++ forcolumn0column3column++ scanf“d” matrixrowcolumn forrow0row3row++ forcolumn0column3column++ ifcolumnrow matrixrowcolumnmatrixrowcolum n//assign the elements as it is if column is greater or equalelse it is 0 else matrixrowcolumn0 forrow0row3row++ forcolumn0column3column++ printf” d” matrixrowcolumn printf“\n” 15 mins

slide 24:

Contact Us Professional Training Institute 32 38/1 2rd FloorHosur Main Road Near Bosch Office Bommanahalli Bengaluru Karnataka-560068 +918951422196

authorStream Live Help