arrays - Write a function to compute the n'th power of a (nxn)matrix in C -
i've added multiplication of 2 matrices algorithm seems it's not working.i need task without using pointers,memory allocation , using basic instructions(for's,while's,...)
void product(double a[][20],double c[][20],int n,int d) { int i, j, k, l; for(l = 1;l <= d; ++l) { for(i = 0; < n; i++) { for(j = 0; j < n; j++) { c[i][j] = 0; for(k = 0; k < n; k++) { c[i][j] += a[i][k]*a[k][j]; } } } } }
this function should calculate a^d , store in c[][20];
your code tries compute a^(2^d), instead calculates a^2 d times.
you can't matrix multiplication in place, because calculate result, overwrite values. need temporary space 1 copy (unless d = 0, 1 or 2).
set c identity matrix , return if d = 0. otherwise set c = copy of a, allocate matrix b, l = 1 d - 1 copy c b, let c = * b.. deallocate b.