In C, a matrix can be represented as a two-dimensional array. The elements of the matrix can be accessed using their row and column indices. Here is an example code for representing and accessing a matrix in C:
```c
#include <stdio.h>
#define ROWS 3
#define COLS 3
int main() {
int matrix[ROWS][COLS] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
// accessing elements of the matrix
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
return 0;
}
```
In this code, we have defined a matrix with 3 rows and 3 columns using a two-dimensional array `matrix[ROWS][COLS]`. The elements of the matrix are initialized using a nested brace-enclosed initializer list.
To access the elements of the matrix, we use two nested loops. The outer loop iterates over the rows of the matrix, and the inner loop iterates over the columns of the matrix. The element at row i and column j is accessed using the index `matrix[i][j]`.
When the code is executed, it will print the following output:
```
1 2 3
4 5 6
7 8 9
```
This output shows the elements of the matrix printed row-wise.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc