i need to put a square matrix on some input power
i tried to copy the algoritm
Code:
http://en.wikipedia.org/wiki/Matrix_multiplication
Code:
#include <stdio.h>
int main(){//start
int rows,cols;
int sum2=0;
printf("enter rows and cols [1..50] ==> ");
scanf("%d %d",&rows,&cols);
int matrix[rows][cols];
int sum[rows][cols];
int transpose [cols][rows];
int index,kndex;
for (index=0;index<rows;index++){
for (kndex=0;kndex<cols;kndex++){
matrix[index][kndex]=0;
sum[index][kndex]=0;
transpose[index][kndex]=0;
}//end inner for
}//end outer for
//stat input
for (index=rows-1;index>=0;index--){
for (kndex=cols-1;kndex>=0;kndex--){
scanf("%d",&matrix[index][kndex]);
transpose [kndex][index]=matrix[index][kndex];
}
}
getchar(); //needed because of scanf()
//end input
//start power multiplication
for (index=0;kndex<power;index++){
for (index=0;kndex<cols;index++){
for (kndex=0;kndex<cols;kndex++){
sum2=sum2+matrix[index][kndex]*matrix[kndex][index];
sum[index][kndex]=sum2;
}
}
}
//end power multiplication
//start print
for (index=0;index<rows;index++){
for (kndex=0;kndex<cols;kndex++){
printf("%d ",sum[index][kndex]);
}
printf("\n");
}
//end print
printf("\n");
return 0;
}//end main func