#include <iostream>
#include <complex>

void print(const std::complex<double> (&matrix)[2][2])
{
	for(const auto& row: matrix) {
		for(const auto& c: row)
			std::cout << c << ' ';
		std::cout << '\n';
	}
}

void multiply(std::complex<double> (&lhs)[2][2], const std::complex<double> (&rhs)[2][2])
{
    std::complex<double> result[2][2];
    for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j)
    	result[i][j] = lhs[i][0]*rhs[0][j] + lhs[i][1]*rhs[1][j];
    for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j)
        lhs[i][j] = result[i][j];
}

void power(std::complex<double> (&matrix)[2][2], unsigned n)
{
    std::complex<double> result[2][2] = {{1, 0}, {0, 1}};
    for(int i = 0; i < n; ++i)
        multiply(result, matrix);
    for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j)
        matrix[i][j] = result[i][j];
}

int main() 
{
	using namespace std::complex_literals;
	std::complex<double> matrix[2][2] = 
	    {{ 1.0 + 0i, 0.0 + 1i}, 
	     {-1.0 + 0i, 0.0 - 1i}};
	print(matrix);
	std::cout << '\n';
	power(matrix, 1);
	print(matrix);
	std::cout << '\n';
	power(matrix, 2);
	print(matrix);
	std::cout << '\n';
}