147k views
4 votes
write a program mexp that multiplies a square matrix by itself a specified number of times. mexp takes a single argument, which is the path to a file

User Dalawh
by
4.8k points

1 Answer

2 votes

#include <bits/stdc++.h>

typedef std::string s;

std::vector<int> m;

void mexp(s path) {

std::fstream data(path);

std::cout << "How many times do you want to multiply?: ";

int i,k,c; std::cin>>i;

while(!data.eof()) {

data>>k;

if(k==0) m.push_back(0);

else m.push_back(pow(k,i));

}

//Print last matrix

for(auto& pr:m) {

std::cout << pr << " ";

c++;

if(c%3==0) std::cout << std::endl;

}

}

int main(int argc, char* argv[]) {

std::cout << "Enter a path: ";

s p; std::cin>>p;

mexp(p);

return 0;

}

User Pfitz
by
4.5k points