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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!