ポインターを使用してユーザー入力行列をn乗する方法を教えてください。今は2の累乗までしか計算できません。

2020-04-09 c++ pointers matrix matrix-multiplication

ユーザー入力のMXM行列をn乗するようにしていますが、2の累乗までしか行列を上げることができません。2より大きい他の数値を入力すると、行列が2の累乗になるだけです。ポインタを使用してどうすればよいですか?

 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 int main() { int M = 0; int N = 0; printf("Enter the size of R: "); scanf("%d",&M); printf("Enter the value of power N: "); scanf("%d",&N); int R[M][M]; //maximum dimension = 5 int result[M][M]; int newR[M][M]; if (M < 1 || M > 5) { printf("Error: Size of M must stay between 1 to 5.\n"); } else { for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("Enter data in R(%d,%d): ",i+1,j+1); scanf("%d",&R[i][j]); } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("R(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } } int sum = 0; for (int i = 0; i < N; i++) { for ( int row = 0 ; row < M ; row++ ) { for (int col = 0 ; col < M ; col++ ) { for (int count = 0 ; count < M ; count++ ) { sum += R[row][count]*R[count][col]; } result[row][col] = sum; printf("%d\n",result[row][col]); sum = 0; } } for (int row = 0; row < M; row++) { for (int col = 0 ; col < M ; col++ ) { newR[row][col] = result[row][col]; // R[row][col] = 0; } } } for (int i = 0; i < M; i++){ for (int j = 0; j < M; j++){ printf("newR(%d,%d) = %d\n",i+1,j+1,newR[i][j]); } } return 0; }``` 
 

Answers

Related