Friday, 16 March 2018

Matrix in C

In C language we can create a matrix by using 2D array. Array is a must known concept that we should know as it is used in many programs.

/* Pre- Processors*/
#include<stdio.h>
#include<conio.h>
#define MAX 15 /* Length of MAX*/

int main()
{
int j,i,m,n;
int a[MAX][MAX];
clrscr();
printf("\t\t\t\t----------------\n");
printf("\t\t\t\t--Array-Matrix--\n");
printf("\t\t\t\t----------------\n");
printf("Enter no. of elements for your Matrix:-");
printf("\n\nEnter no. of rows: ");
scanf("%d",&m);
printf("\nEnter no. of columns: ");
scanf("%d",&n);
printf("\nEnter values:-\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%3d",a[i][j]);
}
printf("\n");
}
getch();
return 0;
}


No comments:

Post a Comment