Write a program to input the elements of 4 x 3 matrix and prints its
elements properly using array.
Answers
Explanation:
include <stdio.h>
int main()
{
int i, j, m, n;
int matrix[10][20];
printf("Enter number of rows : ");
scanf("%d", &m);
printf("Enter number of columns : ");
scanf("%d", &n);
/* Input data in matrix */
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("Enter data in [%d][%d]: ", i, j);
scanf("%d", &matrix[i][j]);
}
}
/* Display the matrix */
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("%d\t", matrix[i][j]);
}
printf("\n");
}
return 0;
#include<stdio.h>
int main()
{
int ;
printf("Enter elements of the matrix:\n");
for( ; ; )
{
for( ; ; )
{
printf("a[%d][%d]=",i,j);
scanf("%d", &a[i][j]);
}
}
printf("The elements of the matrix are:\n");
for( ; ; )
{
for( ; ; )
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
}
Hence, the above is a program that allows you to input elements into a matrix and subsequently print them out.
#SPJ3