Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

processes the command line parameters according to the usage : transpose2 [-2] [

ID: 645796 • Letter: P

Question

processes the command line parameters according to the usage: transpose2 [-2] [-r] [-p d|x] n. This means the program can accept an optional parameter -2, followed by an optional parameter -r, followed by an optional parameter -p (which must be followed by one of the strings d or x or o), followed by an (non-negative) integer n. Valid examples include:

transpose2 0; transpose2 -2 4; transpose2 -r -p d 5; transpose2 -2 -p d 8; transpose2 -p x 16

The program should print out a `usage' message and exit with a status of 1 if the parameters are invalid. Invalid examples include:

transpose2; transpose2 -t 4; transpose2 -p b 5; transpose2 -2 -p x d; transpose2 -p x

Note that your program may treat as valid or invalid the cases where the -2, -r and -p options are repeated or out of order.

dynamically allocates storage for an n by n int matrix A, i.e. the malloc() function must be used. An assert statement should be used to check the allocation succeeded (it might not if very large values of n are given).

if -r was not specified, it initializes each logical element A[i,j] to i*n+j. Otherwise it reads logical element A[i,j] from the standard input in hexadecimal format, with A[i,j] being set to the(i*n+j)'th such value.

performs an in-place transposition of the matrix. If the -2 option was not specified, this should be by a simple nested loop, i.e. one that swaps one element per iteration of the innermost loop. This should be implemented in a separate function which is called from main().
If the -2 option was specified, the transposition should be performed by another function in which the innermost loop swaps four elements, in 2 by 2 blocks, per iteration. This need only work correctly for even n.

if the -p option was specified, prints the matrix A with each row printed (in order) on a line of output. Each element is printed with a " %8d", or " %6x", format specifier, according to whether -p d or -p x, was given in the command line, respectively. This is not preceded by any message.

.

Explanation / Answer

Answer:

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,*a,n;

clrscr();

printf(