see this link:
http://www.phanderson.com/C/mat_mult.html
http://www.phanderson.com/C/mat_add.html
Transposition:
TransposeByteMatrix (void *NewMatrix, void *OldMatrix, int Columns, int Rows)
{
unsigned char *Source;
unsigned char *Destination;
int idx;
int Limit;
int Bias;
Source = (unsigned char *)OldMatrix; /* Could also recast on the fly for every access */
Destination = (unsigned char *)NewMatrix; /* Ditto */
Limit = Rows * Columns;
Bias = 0;
for (idx = 0; idx < Limit; idx++)
{
Destination[Bias] = Source[idx]; /* Move the byte */
Bias = (Bias + Columns) % Limit; /* Compute the position for the next byte */
}
}
2007-03-02 15:06:54
·
answer #1
·
answered by Rainmaker 2
·
0⤊
0⤋
A matrix is just a multi-dimensional array. To be specific, it's a two-dimensional array. So just a couple arrays to hold the type of data you need will work.
Suppose you are making a word search and need a 20x20 matrix. You can define it as
char myMatrix[20][20];
Good enough - you now have a 20x20 matrix. Accessing each position is simple...
myMatrix[10][10] = 'A';
We've just placed the letter a in the middle of the matrix. To fill the entire matrix with the letter A, just do something like:
for (x=0; x<20; x++) {
for (y=0; y<20; y++)
matrix[x][y]='A';
}
You can have a matrix of any datatype - that's up to you. And to make it global or not is also up to you.
2007-03-02 22:36:58
·
answer #2
·
answered by BigRez 6
·
0⤊
0⤋
/*demo of matrix-addition*/
#include
void main()
{
int a[3][3],b[3][3],c[3][3];
int i,j,m,n,p,q;
clrscr();
printf("Enter order of matrix A");
scanf("%d%d",&m,&n);
printf("Enter order of matrix B");
scanf("%d%d",&p,&q);
if((m!=p)||(n!=q))
{
printf("Addn. not possible");
}
else
{
for(i=0;i
{
for(j=0;j
{
printf("Enter element of matrix A");
scanf("%d",&a[i][j]);
}
}
for(i=0;i
{
for(j=0;j
{
printf("Enter element of matrix B");
scanf("%d",&b[i][j]);
}
}
for(i=0;i
{
for(j=0;j
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("Matrix C is");
for(i=0;i
{
for(j=0;j
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
getch();
}
- - - - - - - -- - - - -- - -- - - - - - - - - - - - - - - - --
/*demo of matrix-multiplication*/
#include
void main()
{
int a[3][3],b[3][3],c[3][3];
int i,j,k,m,n,p,q;
clrscr();
printf("enter order of matrix A");
scanf("%d%d",&m,&n);
printf("enter order of matrix B");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("multiplication not possible");
}
else
{
for(i=0;i
{
for(j=0;j
{
printf("enter elements of matrix A");
scanf("%d",&a[i][j]);
}
}
for(i=0;i
{
for(j=0;j
{
printf("enter elements of matrix B");
scanf("%d",&b[i][j]);
}
}
printf("order of matrix C is %dx%d",m,q);
for(i=0;i
{
for(j=0;j
{
c[i][j]=0;
for(k=0;k
{
c[i][j]=c[i][j] + a[i][k] * b[k][j];
}
}
}
printf("matrix C is \n");
for(i=0;i
{
for(j=0;j
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
getch();
}
- - - - - - - - -- - - - -- - - - - -- - - - - - - - - - - - -
//To get transpose matrix of 3x3 input matrix
#include
main()
{
int a[3][3],i,j;
clrscr();
printf("enter elements of 3x3 matrix");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}}
//to print the matrix as entered
printf("\nThe entered matrix is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%3d",a[i][j]);
}
printf("\n");
}
//to transpose the matrix
printf("\nThe transpose matrix is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%3d",a[j][i]);
}
printf("\n");
}
getch();
}
2007-03-05 02:40:02
·
answer #3
·
answered by Innocence Redefined 5
·
0⤊
0⤋