Matlab Queatoin: The test suite generates a random M x N matrix with a random number of rows and columns that is assigned to the variable A . The element values of the matrix are random double precision numbers that fall in the range from -10 to 10. The matrix has between 5 and 10 rows and between 5 and 10 columns. Assuming A is defined in the workspace, write a script with commands to perform the operations described below and assign the results to the indicated variable names.
Create a new 2 x N matrix, B, that consists of the first and last rows of A.
Create a new 2 x 2 matrix, C, that consists of the elements at the four corners of A.
Create a new M-1 x N-1 matrix, D, that consists of the second through last columns in the second through last rows of A.
Here is the question reamind" %Enter the commands for your script mfile here. Be sure to assign the matrices specified in the problem statement to the indicated variable names.
B = A;
C = A;
D = A;"
Solution for problem( C programming)
Program :-
#include<stdio.h>
int main()
{
int
A[100][100],B[100][100],C[100][100],D[100][100],i,j,rows,columns,k=0,l=0,m=0,n=0,o=0,p=0;
printf("Enter number of Rows (between 5 to 10) :-");
scanf("%d",&rows);
printf("Enter number of Columns (between 5 to 10) :-");
scanf("%d",&columns);
printf("Enter values into Matrix A :-\n");
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
scanf("%d",&A[i][j]);
}
}
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
if(i==0 || i==rows-1) //Creating B matrix.
{
B[o][p++]=A[i][j];
if(p>columns-1)
{
o++;
p=0;
}
}
if((i==0 && j==0) || (i==0 && j==columns-1) ||
(i==rows-1 && j==0) || (i==rows-1 && j==columns-1))
//Creating C matrix.
{
C[k][l++]=A[i][j];
if(l>1)
{
k++;
l=0;
}
}
if(i>0 && j>0) // Create D matrix.
{
D[m][n++]=A[i][j];
if(n==columns-1)
{
m++;
n=0;
}
}
}
}
printf("Matrix B is :-\n");
for(i=0;i<2;i++)
{
for(j=0;j<columns;j++)
{
printf("%d\t",B[i][j]);
}
printf("\n");
}
printf("\nMatrix C is :-\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",C[i][j]);
}
printf("\n");
}
printf("\nMatrix D is :-\n");
for(i=0;i<rows-1;i++)
{
for(j=0;j<columns-1;j++)
{
printf("%d\t",D[i][j]);
}
printf("\n");
}
return 0;
}
Output :-
Enter number of Rows (between 5 to 10) :-4
Enter number of Columns (between 5 to 10) :-5
Enter values into Matrix A :-
1 2 3 4 5
11 12 13 14 15
21 22 23 24 25
31 32 33 34 35
Matrix B is :-
1 2 3 4 5
31 32 33 34 35
Matrix C is :-
1 5
31 35
Matrix D is :-
12 13 14 15
22 23 24 25
32 33 34 35
Note :- All B,C,D matrices are priented separetly.
Thank you!
Get Answers For Free
Most questions answered within 1 hours.