Write a program to take the user input matrix.
C Program
#include <stdio.h>int main(){int n, m;printf("Enter the dimension of the matrix: ");scanf("%d%d", &n, &m);int matrx[n][m];printf("Enter the matrix elements:\n");for (int i = 0; i < n; i++){for (int j = 0; j < m; j++){scanf("%d", &matrx[i][j]);}}printf("Matrix is: \n");for (int i = 0; i < n; i++){for (int j = 0; j < m; j++){printf("%d ", matrx[i][j]);}printf("\n");}return 0;}
Input:
Enter the dimension of the matrix: 3 4
Enter the matrix elements:
1 2 3 4
5 6 7 8
9 2 3 4
Output:
Matrix is:
1 2 3 4
5 6 7 8
9 2 3 4
No comments:
Post a Comment