>
> In this project you will work with matrices of arbitrary order. You have to
> implement a Matrix data structure, which stores the order of the matrix and
> its elements. Your program should be able to read a matrix from a text file,
> the format of which is provided below:
>
> R C
> A11 A12 . . . A1C
> A21 A22 . . . A2C
> . . . . . .
> . . . . . .
> AR1 AR2 . . . ARC
>
> where R and C are integers specifying the order of the matrix, and the
> elements of the matrix are floating-point numbers.
>
> Furthermore, you need to implement the following matrix operations:
> Addition
> Subtraction
> Multiplication (using Strassens algorithm)
> Transpose
> Inverse
>
> For addition, subtraction, and multiplication, your program should read two
> matrices and check their dimensions before proceeding with the algorithm. For
> inverse, your program should make sure the matrix is nonsingular before
> proceeding. After each operation, your program should print the input and
> output matrices on the screen.
>
> This program should be menu-driven.
i have amke this code
but its not working
plz remove the errors
//********************HEre IS The Code**********************
#include<stdio.h>
#include<conio.h>
# define n 100
int a,i,k,j,c1,c2,r1,r2;
int m1[n][n],m2[n][n],m3[n][n];
void transpose();
void addition();
void subtraction();
//void inverse();
void multiplicaton();
// power function//
int power(int a1,int b1){
int i1;
for(i1=0;i1<=b1;i1++){
if(i1==0){
a1=1;
}
else{
a1=a1*10;
}
}
return a1;
}
//*****************TRANSPOSE***************
void transpose()
{
printf("\n Enter the number of rows:-");
scanf("%d",&r1);
printf("\n Enter the number of columns:-");
scanf("%d",&c1);
printf("\n Enter the element :-");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&m1[i][j]);
m2[j][i]=m1[i][j];
}
}
/*Displaying transpose of matrix*/
printf("\n Transpose of Matrix is:-\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("\t%d",m2[i][j]);
printf("\n");
}
}
//***************ADDITION***********************
void addition()
{
printf("\n how many row and coloum in Matrix one:-");
scanf("%d%d",&r1,&c1);
printf("\n How amny row and coloum in Matrix two:-");
scanf("%d%d",&r2,&c2);
if((r1==r2)&&(c1==c2))
{
printf("\n Addition is possible:-");
printf("\n Input Matrix one:-");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[i][j]);
}
printf("\n Input Matrix two:-");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
}
/* Addition of Matrix*/
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
m3[i][j]=m1[i][j]+ m2[i][j];
}
printf("\n The sum is:-\n");
for(i=0;i<c1;i++)
{
for(j=0;j<r1;j++)
printf("%5d",m3[i][j]);
printf("\n");
}
}
else
printf("\n Addition is not possible:-");
}
//****************MULTIPLICATION********************
void multiplication()
{
printf("\n Enter number of row and coloum in matrix one:-");
scanf("%d%d",&r1,&c1);
printf("\n Enter number of row and coloum in matrix two:-");
scanf("%d%d",&r2,&c2);
if(c1==r2)
{
printf("\n Multiplication is possible:-");
printf("\n Input value of Matrix one:-");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[i][j]);
}
printf("\n Input value of Matrix two:-");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
}
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
{
m3[i][j]=0;
for(k=0;k<c1;k++)
m3[i][j]=m3[i][j]+m1[i][k]*m2[k][j];
}
/*Displaying final matrix*/
printf("\n Multiplication of Matrix:-\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
printf("\t%d",m3[i][j]);
printf("\n");
}
}
else
printf("\n Multiplication is not possible");
}
//******************** subtraction *****************
void subtraction()
{
printf("\n how many row and coloum in Matrix one:-");
scanf("%d%d",&r1,&c1);
printf("\n How amny row and coloum in Matrix two:-");
scanf("%d%d",&r2,&c2);
if((r1==r2)&&(c1==c2))
{
printf("\n Subtraction is possible:-");
printf("\n Input Matrix one:-");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[i][j]);
}
printf("\n Input Matrix two:-");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
}
/* subtraction of Matrix*/
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
m3[i][j]=m1[i][j]- m2[i][j];
}
printf("\n The result after subtraction is:-\n");
for(i=0;i<c1;i++)
{
for(j=0;j<r1;j++)
printf("%5d",m3[i][j]);
printf("\n");
}
}
else
printf("\n Subtraction is not possible:-");
}
//******************** MAIN *********************
int main()
{
FILE *fp;
char aa[n];
fp=fopen("matrix.txt","r");
int ia=0;
while(1){
aa[ia]=fgetc(fp);
if(aa[ia]==EOF)
break;
//printf("%c",aa[ia]);
ia++;
}
int da=0,ela=0,pa,na,ca,ka=0,ja=0,ba[ia],once=0;
while(aa[ja]!=EOF && aa[ja]!='\0'){
while(aa[ja]!=' '&& aa[ja]!='\n' &&
aa[ja]!='\t' && aa[ja]!=EOF && aa[ja]!=','){
ca=ja;
while(aa[ja+1]!=' '&& aa[ja+1]!='\n' &&
aa[ja+1]!='\t' && aa[ja+1]!=EOF && aa[ja+1]!=','&& once==0){
da=da++;
ja++;
}
once=1;
ja=ca;
na=aa[ja]-48;
//printf("\n%d\n",d);
pa=power(10,da);
//p=pow(10,d);
//printf("\n%d\n",p);
ela=ela+(na*pa);
ba[ka]=ela;
da--;
ja++;
}
// printf("\n%d\n",ba[ka]); // sigle array
which stores the element first two contains order
ka++;
ela=0;
ja++;
da=0;
once=0;
}
// c=a[j]-48;
//d=d+c;
// printf("\n%d\n\n",j);
// printf("\n cis %d\n",d);
//b[k]=d;
//printf("\n%d\n",b[k]);
//j++;
//printf("\n%d",j);
//}
//d=0;
//k++;
//j++;
// }
int row=ba[0],col=ba[1];
int ya,mat[row][col],qa,wa,ea=2;
// printf("\%d",b[e]);
for(qa=0;qa<row;qa++){
// printf("\n",b[e]);
for(wa=0;wa<col;wa++){
mat[qa][wa]=ba[ea];
ea++;
//printf("\n",b[e]);
//a[i][j]=k;
}
}
printf("matrix1 \n");
for(qa=0;qa<ba[0];qa++){
for(wa=0;wa<ba[1];wa++){
printf("%d \t",mat[qa][wa]);
}
printf("\n");
}
//printf("\n%d last is
",ba[ka-2]);
//clrscr();
while(1)
{
printf("\n 1. Transpose of Matrix:-\n");
printf("\n 2. Addition of Matrix:-\n");
printf("\n 3. Multiplication of Matrix:-\n");
printf("\n 4. Subtraction of matrix\n");
printf("\n 5. Inverse of Matrix:-\n");
printf("\n Enter your choice:-");
scanf("%d",&a);
switch(a)
{
case 1 :
transpose();
break;
case 2:
addition();
break;
case 3:
multiplication();
break;
case 4:
subtraction();
break;
case 5:
// inverse();
break;
}
getch();
}
getch();
return 0;
}
---------------------------------
Get easy, one-click access to your favorites. Make Yahoo! your homepage.
[Non-text portions of this message have been removed]