Lesson 13 of 23

2D Arrays: Matrices2D Arrays: Matrices

11 min 30 XP

int m[3][3] என்பது 3 rows, 3 columns உள்ள அட்டவணை. m[i][j] என்று அணுகுவோம். இரண்டு nested loops மூலம் படிக்கவும், print செய்யவும் முடியும்.

int m[3][3] is a table with 3 rows and 3 columns, accessed as m[i][j]. Two nested loops read and print it.

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

Matrix பெருக்கல் (A × B): C[i][j] = Σ A[i][k] × B[k][j]. மூன்று nested loops. இது ஒரு பிரபல interview program.

Matrix multiplication: C[i][j] = Σ A[i][k] × B[k][j], three nested loops. A popular interview program.

Challenge

+30 XP

n (n × n matrix) மற்றும் matrix-ஐப் படித்து, இரண்டு diagonals-ன் கூட்டுத்தொகையையும் print செய்யுங்கள். Input: 3 1 2 3 4 5 6 7 8 9 Output: Main: 15 Other: 15

Read n and an n × n matrix. Print the sum of each diagonal. Input: 3 1 2 3 4 5 6 7 8 9 Output: Main: 15 Other: 15

Output Loading C (first time takes a few seconds)
Press Run to see the result here.