Pages

Ads 468x60px

Saturday, 2 June 2012

C PROGRAM FOR FINDING MATRIX ADDITION


C PROGRAM FOR FINDING MATRIX ADDITION

                   Below is the code to calculate matrix inverse of a matrix of arbitrary
 size (order) by using analytic solution. This method is known to be slow
 for very large matrix because of the recursion. However, I used this
 mainly for calculating inverse of 4×4 matrices and it worked just fine.
 You can also use CalcDeterminant and GetMinor to calculate determinant of a matrix.





CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,a[10][10],i,j,m,n,b[10][10],z[10][10];
clrscr();
printf("Enter r and c value:");
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
for(m=1;m<=r;m++)
{
for(n=1;n<=c;n++)
{
printf("b[%d][%d]=",m,n);
scanf("%d",&b[m][n]);
}
}
// z[i][j]=0;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
z[i][j]=(a[i][j]+b[i][j]);
}
}
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("%d\t",z[i][j]);
}
printf("\n");
}
getch();
}

0 comments:

Post a Comment

Total Pageviews