English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

#include

void mult_matrices(int a[][3], int b[][3], int result[][3]);
void print_matrix(int a[][3]);
void carpma(int a[][3], int b[][3], int result[][3]);
void cıkarma (int a[][3], int b[][3], int result[][3]);
void bolme(int a[][3], int b[][3], int result[][3]);

void main(void)
{
int p[3][3] = { {1, 3, -4}, {1, 1, -2}, {-1, -2, 5} };
int q[3][3] = { {8, 3, 0}, {3, 10, 2}, {0, 2, 6} };
int r[3][3];
int i,j,temp;

mult_matrices(p, q, r);
print_matrix(r);
plus(p, q, r);
print_matrix(r);
minus(p, q, r);
print_matrix(r);
divide(p, q, r);
print_matrix(r);

printf("\nMatrix 1:\n");
print_matrix(p);

printf("\nMatrix 2:\n");
print_matrix(q);

printf("\nResult:\n");
print_matrix(r);


clrscr();

for( i=0;i<3;i++) {
for( j=0;j<3;j++)
scanf("%d",&p[i][j]);
}
i=0;
j=0 ;
for(int b=0;b<2;b++){

temp= p[i][j+1];
p[i][j+1]=p[i+1][j];
p[i+1][j]=temp;

i=i+1;
j=j+1;
if(b==1){
i=0;
j=0;
temp=p[i][j+2];
p[i][j+2]=p[i+2][j];
p[i+2][j]=temp;
}
}
printf("\nthe transpose of the matrix is:\n");
for(i=0;i<3;i++){
for(j=0;j<3;j++)
printf("%d\t",p[i][j]);
printf("\n");
}
getch();
}





void mult_matrices(int a[][3], int b[][3], int result[][3])
{
int i, j, k;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
for(k=0; k<3; k++)
{
result[i][j] = a[i][k] + b[k][j];
}
}
}
}
void plus(int a[][3], int b[][3], int result[][3])
{
int i, j;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
result[i][j] = a[i][j] * b[i][j];
}
}


void minus(int a[][3], int b[][3], int result[][3])
{
int i, j;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
result[i][j] = a[i][j] - b[i][j];
}
}
}

void divide(int a[][3], int b[][3], int result[][3])
{
int i, j;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
result[i][j] = a[i][j] / b[i][j];
}
}
}

void print_matrix(int a[][3])
{
int i, j;
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%d\t", a[i][j]);
}

2007-01-18 23:49:55 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

OK, to start with, you didnt declare the functions, "plus(), minus(), and divide()". you got the other 2 though ("print_matrix(), and mult_matrices()").

the next problem is you are trying to pass pointers in your functions, but your function is expecting an integer. you are passing like this "p,q,r", which are pointers to your matrix, but your functions are expecting an int (one number).

next, the way you declare your functions is wrong. example: "void mult_matrices(int a[][3], int b[][3], int result[][3]);"
should be "void mult_matrices(int *a, int *b, int* result);" now you are passing pointer to the arrays!

2007-01-19 01:01:19 · answer #1 · answered by justme 7 · 0 0

I saw plus(p,q,r); minus(p,q,r); divide(p,q,r). These are supposed to be functions operating on int arrays p, q, r. Problem is, these functions (minus, plus, divide) were not declared before usage. You can do it like you did for void mult_matrices(int,int,int):


//Code Starts
void mult_matrices(int a[][3], int b[][3], int result[][3]);
....
void mult_matrices(int a[][3], int b[][3], int result[][3])
{
Do Stuff....
}
// Code Ends

I hope this solves it for you.

Also, your code is difficult to read due to no-indentation. Could you adopt some indentation so you can easily go thru your own code fast. Unless it's justified by the web system.

2007-01-19 00:21:21 · answer #2 · answered by Anonymous · 0 0

I understand the code but NOT the question!

You have already asked about this code!

2007-01-18 23:56:19 · answer #3 · answered by Tempest 3 · 0 0

If your programming is anything like your question asking, it's most likely a syntax error ;)

2007-01-19 00:14:27 · answer #4 · answered by Anonymous · 1 0

fedest.com, questions and answers