imprimir matriz
Here is an example of how to print a matrix in C:
#include <stdio.h>
void printMatrix(int matrix[][3], int rows, int columns) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}
int main() {
int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int rows = 3;
int columns = 3;
printMatrix(matrix, rows, columns);
return 0;
}
This code defines a function called printMatrix
that takes a 2D array matrix
, the number of rows, and the number of columns as parameters. The function then uses nested for loops to iterate over each element in the matrix and prints it using the printf
function. After defining the printMatrix
function, the main function creates a sample matrix, calls the printMatrix
function, and returns 0 to indicate successful execution. When you run this code, it will print the matrix as follows:
1 2 3
4 5 6
7 8 9
Feel free to modify the matrix dimensions and values according to your needs.