I got this simple operation of 2 equal matrix multiplication:
How to change it so if i enter a number
it will put the matrix into the power of the input number.
How do i transform some how this simple multiplication operation into a power operation.
Ii have tried to use temporary matrix to save the local multiplication.
and multiply by it on the next step
but its not working
??
Code:
#include <stdio.h>
int main(){//star
int rows,cols,jndex,input;
int sum2=0;
printf("enter rows and cols [1..50] ==> ");
scanf("%d %d",&rows,&cols);
int matrix[rows][cols];
int sum[rows][cols];
int temp[rows][cols];
int transpose [cols][rows];
int index,kndex,tndex,gndex,lndex;
printf("enter power:");
scanf("%d",&input);
for (index=0;index<rows;index++){
for (kndex=0;kndex<cols;kndex++){
matrix[index][kndex]=0;
sum[index][kndex]=0;
temp[index][kndex]=0;
transpose[index][kndex]=0;
}//end inner for
}//end outer for
printf("enter numbers in a row for a matrix:"); //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 operation
//start temp=matrix
for (gndex=0;gndex<rows;gndex++){
for (lndex=0;lndex<cols;lndex++){
temp[index][kndex]=matrix[index][kndex];
}//end inner for
}//end outer for
//end temp=matrix
for (tndex=0;tndex<input;tndex++){
for(index=0;index<rows;index++) {
for(jndex=0;jndex< cols;jndex++) {
sum[index][jndex]=0;
for(kndex=0;kndex<cols;kndex++) {
sum[index][jndex] = sum[index][jndex] + temp[index][kndex] * matrix[kndex][jndex];
}
}
}
//start temp=sum
for (gndex=0;gndex<rows;gndex++){
for (lndex=0;lndex<cols;lndex++){
temp[index][kndex]=sum[index][kndex];
}//end inner for
}//end outer for
//end temp=sum
}
//end power operation
//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