I have some code here to multiply matrices. It's not working as designed. Any suggestions? I want it to multiply a matrix then continue to do so until it reaches n. So, the desire output is A^n, with input n.
Code:
#include <stdio.h>
#include <math.h>
void multmtrx(int A[2][2], int B[2][2], int result[2][2])
{
for (int i=0; i<2; i++){
for (int j=0; j<2; j++)
for (int k=0; k<2; k++)
result[i][j]=A[i][k]*B[k][j];}
}
void printmtrx(int result[2][2])
{
printf("\nThis is your new matrix.\n");
for (int i=0; i<2; i++)
{ for (int j=0; j<2; j++)
printf(" %d", result[i][j]);
printf("\n");
}
}
void main()
{
int sigma_x[2][2]={{0,1},{1,0}};
/* Imaginary numbers needed */
/* int sigma_y[2][2]={{0,0},{0,0}}; */
int sigma_z[2][2]={{1,0},{0,-1}};
int result[2][2]={{0,0},{0,0}};
int n;
printf("\nHow many times do you want to multiply the matrix?");
scanf("%dd", &n);
printf("\nThe matrix will be multiplied %d times.", n);
for (int i=2; i<=n; i++){
multmtrx(sigma_x, sigma_z, result);
printmtrx(result);}
printf("\nAgain?");
scanf("%dd", &n);
if (n==1) main();
}