100% found this document useful (1 vote)
2K views2 pages

Toughest 2D Array Problems for Students

This document contains 21 practice questions related to 2D arrays in C programming. The questions cover a range of topics including inputting and displaying 2D arrays, calculating sums and averages of elements, finding transpose and diagonal elements, matrix addition/multiplication, checking for identity/sparse matrices, determinant calculation, and more. Memory addressing of 2D arrays is also discussed.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views2 pages

Toughest 2D Array Problems for Students

This document contains 21 practice questions related to 2D arrays in C programming. The questions cover a range of topics including inputting and displaying 2D arrays, calculating sums and averages of elements, finding transpose and diagonal elements, matrix addition/multiplication, checking for identity/sparse matrices, determinant calculation, and more. Memory addressing of 2D arrays is also discussed.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
  • 2D Array Practice Questions

2D Array Practice Questions

1. WAP to input a 2D array of size M*N and display it in tabular form.


2. WAP to input a 2D array of size M*N and find the sum and average of all the elements.
3. WAP to input a 2D array of size M*N and find the sum of individual rows and individual columns.
4. WAP to input a 2D array of size M*N and display boundary elements in matrix form.
5. WAP to input a 2D array of size M*N and display the transpose of it.
6. WAP to input a 2D array and find the sum of its diagonal elements.
7. WAP to input a 2D array and display diagonal elements in matrix form.
8. WAP to input 2 matrices from the user and add them.
9. WAP to input a matrix and check if its identity matrix or not.
10. WAP to input a matrix of order M*N and check if it’s sparse or dense matrix.
11. Write a program in C to calculate determinant of a 3 x 3 matrix.
12. Write a program to keep records and perform statistical analysis for a class of students. The
class may have up to 10 students. There are three quizzes during the term for computer
programming. Each student is identified by a four digit roll no. The program will print the
student scores and calculate and print the following statistics
1. High score & Low score for each quiz along with the roll number of that student.
2. Average of Each Quiz and overall average of all the 3 quizzes
3. Highest Average and Lowest average of all the three quizzes along with quiz no.
4. Highest marks & lowest marks of each student in the 3 quizzes along with the quiz no.
13. WAP to input 2 matrixes and multiply them.
14. WAP to input a matrix and print its upper triangular matrix.
15. WAP to input a matrix and print its Lower triangular matrix.
16. WAP to input a matrix and print it in zig zack form.
Example :- if matrix is 1 2 3 4
5678
9123
4591
Then output matrix will be
1234
8765
9123
1954
17. Suppose there is a game known as “MATCH THE TABLES”, in which the player picks up two
tables(each having 10 rows and 10 columns) and matches them. If out of 100 entries at least 90
corresponding entries match then the tables are said to be identical and the player is declared
the winner. Wap in ‘C’ to implement the above game.
18. Which of the following initializations of a 2d array are valid?

(i) int abc[2][2] = {1, 2, 3 ,4 } (ii) int abc[][] = {1, 2, 3 ,4 }


(iii) int abc[][] = {1, 2, 3 ,4 } (iv) int abc[2][] = {1, 2, 3 ,4 }
19. An array =X [-15……….10, 15……………40] requires one byte of storage. If beginning location is
1500 determine the location of X [5][20]for data stored as
(i) Column major wise (ii) Row major wise.
20. Consider the following declaration of a ‘two-dimensional array in C:

char a[100][100];

Assuming that the main memory is byte-addressable and that the array is stored starting from
memory address 0. Find the address of a[40][50] using row and column major.
21. Let A be a square matrix of size n x n. Consider the following program. What is the expected
output?
C = 100;
for(i=0;i<n;i++)
    for(j=0;j<n;j++)
    {
        Temp = A[i][j] + C;
       A[i][j] = A[j][i];
        A[j][i] = Temp – C;
    }
for(i=0;i<n;i++)
    for(j=0;j<n;j++)
       printf(“%d ”,A[i][j]);

Common questions

Powered by AI

To determine the storage location of X[5][20] in a 2D array declared with specific index ranges like [-15 to 10] and [15 to 40], calculate as if the beginning address is adjusted by the offset of these negative indices. The base address 1500 is adjusted using the formula for row-major order, considering X[row_start][column_start]. This reveals the importance of index mapping in data storage and retrieval, emphasizing the role of array bounds in memory allocation .

To calculate the determinant of a 3x3 matrix in C, you follow the formula: det(A) = a(ei − fh) − b(di − fg) + c(dh − eg) for a matrix A with elements a to i arranged in a 3x3 form. The theoretical importance of determinants in linear algebra lies in their ability to provide structural insights about the matrix, such as invertibility, and the volume scaling factor for transformations. Determinants also play a crucial role in systems of linear equations and eigenvalues, as they are zero if and only if the matrix is singular (non-invertible).

To find the sum and average of the elements in a 2D array, iterate over each element using nested loops to accumulate their values in a sum variable. Divide the final sum by the total number of elements, which is the product of the number of rows and columns, to get the average. This process is significant in data analysis as it allows for the quantification of central tendency and dispersion, providing a summary metric for large datasets to inform decision making .

Matrix addition involves element-wise addition of two matrices of the same dimensions, while multiplication involves a more complex calculation, where each element of the resulting matrix is a sum of products of corresponding elements from the rows and columns of the two matrices being multiplied. Addition is simpler but limited to matrices of identical size, whereas multiplication, applicable to a broader range of matrix pairs, is essential for solving linear equations, transformations, and more complex operations like determinant and eigenvalue computation .

The described program effectively transposes the matrix and modifies each element by an offset controlled by variable C. Repeatedly transposing a square matrix using this approach can create unnecessary computational overhead and accumulate errors if the elements are not properly reassigned, potentially losing original data meaning. Furthermore, if C is large, the temporary variables may exceed storage capacity leading to overflow. This method demonstrates the complexities of in-place operations on matrices where iterative changes could impact both performance and data integrity .

In the 'MATCH THE TABLES' game, two tables are considered identical if at least 90 out of 100 corresponding entries match across both tables. To implement this game in C, you would input two 10x10 matrices, then iterate through each corresponding entry of both matrices, counting the number of matches. If the count reaches 90, the tables are deemed identical, and the player wins. This requires understanding of 2D arrays and nested loops to compare entries efficiently .

Calculating the high and low scores across quizzes provides performance benchmarks, helping educators identify student outliers and adjust teaching strategies. To implement programmatically, maintain an array for each quiz's scores. Use loops to traverse each array, comparing values to track the maximum and minimum scores. Additionally, store associated roll numbers for direct reference. This offers quantitative data for refined educational assessments and interventions .

To check if a matrix is an identity matrix, ensure it is square, with ones along the diagonal and zeros elsewhere. Iteratively verify that a[i][j] is 1 when i equals j and 0 otherwise, using conditional checks inside nested loops. An identity matrix is vital because it acts as the multiplicative identity in matrix multiplication, preserving any matrix it multiplies, much like the number 1 does in scalar arithmetic .

Determining whether a matrix is sparse or dense is important for optimizing both computation and storage. Sparse matrices, which contain a high proportion of zero elements, can be stored more efficiently using specialized data structures like Compressed Sparse Row (CSR) or Compressed Sparse Column (CSC), reducing memory and speeding up computational algorithms. Dense matrices, on the other hand, might require more memory and computational power if stored naively, as their operations often involve handling more non-zero entries .

To determine the address of a[40][50] in a two-dimensional char array stored in a byte-addressable memory starting at address 0, you must decide between row-major or column-major ordering. In row-major order, the address is calculated as base_address + (row_index * number_of_columns + column_index) * size_of_data_type. Given values: base_address = 0, row_index = 40, column_index = 50, number_of_columns = 100, and size_of_data_type = 1 byte, the address is 0 + (40 * 100 + 50) * 1 = 4050 .

2D Array Practice Questions
1.
WAP to input a 2D array of size M*N and display it in tabular form.
2.
WAP to input a 2D array
19. An array =X [-15……….10, 15……………40] requires one byte of storage. If beginning location is
1500 determine the location of

You might also like