Question
Fourth: Matrix Exponentiation This program will test your ability to manage memory using malloc() and provide some experience dealing with 2D arrays in C. (program
Fourth: Matrix Exponentiation
This program will test your ability to manage memory using malloc() and provide some experience dealing with 2D arrays in C. (program in C)
Your task is to create a program that computes Mn where M is a square matrix M (the dimensions of the matrix will be k x k where k is the number of rows) and a number n 0. In summary, you need to multiply the matrix with itself n times.
Input-Output Format
The program will take the file name as input. The first line in the file will provide the number of rows in the matrix. The subsequent lines will provide the contents of the matrix. The numbers are tab separated. The last line in the file after the contents of the matrix will contain the exponent n. For example, a sample input file file.txt:
3
1 2 3
4 5 6
7 8 9
2
The first number (3) refers to the number of rows in the square matrix. The dimensions of the matrix will be 3x3. The exponent is 2. Hence, the program is required to compute M2 . You can assume that the input will be properly formatted. The output on executing the program with the above input is shown below.
The output numbers should be tab separated. There should not be extra tabs or spaces at the end of the line or the end of the file.
$./fourth file1.txt
30 36 42
66 81 96
102 126 150
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started