If you have any doubts, please give me comment...
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("Usage: ./mexp file1.txt\n");
return 0;
}
FILE *fp;
fp = fopen(argv[1], "r");
if (fp == NULL)
{
printf("Unable to open file\n");
return 0;
}
int i, j, k, m, n, times;
fscanf(fp, "%d", &n);
int **M = (int **)malloc(n * sizeof(int *));
int **M1 = (int **)malloc(n * sizeof(int *));
int **res = (int **)malloc(n*sizeof(int *));
for (i = 0; i < n; i++){
M[i] = (int *)malloc(n * sizeof(int));
M1[i] = (int *)malloc(n * sizeof(int));
res[i] = (int *)malloc(n * sizeof(int));
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
fscanf(fp, "%d", &M[i][j]);
M1[i][j] = M[i][j];
}
}
fscanf(fp, "%d", ×);
for (m = 0; m < times-1; m++)
{
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
res[i][j] = 0;
for (k = 0; k < n; k++)
res[i][j] += M[i][k] * M1[k][j];
}
}
for(i=0;i<n; i++){
for(j=0;j<n; j++){
M1[i][j] = res[i][j];
}
}
}
for(i=0;i<n; i++){
for(j=0;j<n; j++){
printf("%d ", res[i][j]);
}
printf("\n");
}
fclose(fp);
return 0;
}
Write a program mexp that multiplies a square matrix by itself a specified number of times、mexp...
C++ CODE: The matrix class consists of two files: matrix.h and matrix.cpp. The class has the following definition: matrix -size:int -mat:int** ---------------- +matrix(file:string) +~matrix() +operator +(add:matrix*):matrix & +operator-(sub:matrix*):matrix & +friend operator<<(out:ostream &, t:const matrix&):ostream & +displayRow(r:int):void The class variables are as follows: • size: the number of rows and columns in a square matrix • mat: the integer matrix that contains the numeric matrix itself. The methods have the following behaviour: 2 • matrix(file:string): The default constructor. It receives the...
*** Write a function called reverse_diag that creates a square matrix whose elements are 0 except for 1s on the reverse diagonal from top right to bottom left. The reverse diagonal of an nby- n matrix consists of the elements at the following indexes: (1, n), (2, n-1), (3, n-2), … (n, 1). The function takes one positive integer input argument named n, which is the size of the matrix, and returns the matrix itself as an output argument. Note...
Write the following C++ program that searches for specified words hidden within a matrix of letters. 1) Read a file that the user specifies. The file will first specify the dimensions of the matrix (e.g., 20 30). These two numbers specify the number of rows in the matrix and then the number of columns in the matrix. 2) Following these two numbers, there will be a number of rows of letters. These letters should be read into your matrix row...
Write a program that searches for specified words hidden within a matrix of letters. C++ HELP -pls keep basic as possible, thanksssss 1. Read a file that the user specifies. The file will first specify the dimensions of the matrix (e.g., 20 30). These two numbers specify the number of rows in the matrix and then the number of columns in the matrix. 2. Following these two numbers, there will be a number of rows of letters. These letters should...
This is being done in c using command line in Linux
1.1 llist: Linked list Write a program llist that maintains and manipulates a sorted linked list of integers according to instructions received from standard inpu. The linked list is maintained in order, meaning that each integer will be larger than the one preceeding it. 1list maintains a linked list containing zero or more integers, ordered from least to greatest llist will need to allocate space for new nodes as...
4A. Write a CUDA host program that reads a character type matrix A and integer type matrix B of size mxn. It produces an output string STR such that, every character of A is repeated n times (where n is the integer value in matrix B which is having the same index as that of the character taken in A). Solve this using 1D Block. Example: 1 2 4 3 e X a M Output String STR: pCCaaaaPPPeeXXXXaaaMM 4B. Write...
This assignment requires you to write a program to implement an odd-order Magic Square. Prompt the user to enter the “order” of the square and then produce for the user a magic square of that order. Run your code for at least four different inputs – all odd. ODD ORDER MAGIC SQUARES 1. Start by placing 1 in the middle column of the top row. 2. Continue by always placing the next number (say k+1) in the square diagonally up...
Please write code in java You’re given a chess board with dimension n x n. There’s a king at the bottom right square of the board marked with s. The king needs to reach the top left square marked with e. The rest of the squares are labeled either with an integer p (marking a point) or with x marking an obstacle. Note that the king can move up, left and up-left (diagonal) only. Find the maximum points the king...
Please write a C++ Program for the following problem >> Vector: Calculation the sum of each two adjacent Numbers.... >>【Description】 Read integer numbers from keyboard and store them into a vector. Calculation the sum of each two adjacent Numbers, store the result into another vector. Then output the result inversely. For example, if the input is 1 2 3 4 5 then the output is 9 7 5 3 【 Input】 There are 5 test cases. For each case, there...
Use
c++ as programming language. The file needs to be created ourselves
(ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...