Accept and display an matrix using array

Accept and display an matrix using array

Program:


#include<stdio.h>
void main()
{
float a[3][3];
int i,j;
printf("Enter numbers for matrix in rowwise manner:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%f",&a[i][j]);
}
}
printf("\nEntered matrix is:\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%f\t",a[i][j]);
}
printf("\n");
}
}

Output:




Explanation:

For displaying an matrix we need to use 2D array.

In 2D array we have 1st subscript for row and 2nd subscript for column.



No comments:

Post a Comment