Write a C program to display a 2-dimensional matrix.
#include <stdio.h>
int main() {
int rows, cols;
// Input number of rows and columns
printf("Enter number of rows: ");
scanf("%d", &rows);
printf("Enter number of columns: ");
scanf("%d", &cols);
int matrix[rows][cols];
// Input elements of the matrix
printf("Enter elements of the matrix:\n");
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
printf("Element [%d][%d]: ", i + 1, j + 1);
scanf("%d", &matrix[i][j]);
}
}
// Display the matrix
printf("\nThe 2D matrix is:\n");
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
printf("%d\t", matrix[i][j]);
}
printf("\n");
}
return 0;
}