CS201 Assignment 2 ...

Share:
Clear all

# [Solved] CS201 Assignment 2 Solution Spring 2021

(@zero)
Eminent Member
Joined: 5 months ago
Posts: 46
Topic starter

Joined: 3 years ago
Posts: 6411

CS201 Assignment 2 Solution Spring 2021

CS201 Assignment 2 Spring 2021 solution idea:

CODE:

```#include <iostream>

#include <conio.h>

using namespace std;

int ShowMatrix()

{

int row1=2;

int column1=2;

int matrix[2][2] = { {7, 15} , {13, 5}  };

cout<<"The matrix is:"<<endl;

for(int i=0; i<row1; ++i) {

for(int j=0; j<column1; ++j)

cout<<matrix[i][j]<<" ";

cout<<endl;

}

}

int showTranspose ( )

{

int transpose[2][2], row=2, column=2, i, j;

int matrix[2][2] = { {7, 15} , {13, 5}   };

cout<<endl;

for(i=0; i<row; ++i)

for(j=0; j<column; ++j) {

transpose[j][i] = matrix[i][j];

}

cout<<"Transpose of matrix:"<<endl;

for(i=0; i<column; ++i) {

for(j=0; j<row; ++j)

cout<<transpose[i][j]<<" ";

cout<<endl;

}

}

int           calculateDeterminant()

{

int  determMatrix[2][2],determinant;

int matrix[2][2] = { {7, -15} , {13, 5}  };

determinant = ((matrix[0][0] * matrix[1][1]) -

(matrix[0][1] * matrix[1][0]));

cout << "\nThe Determinant of 2 * 2 Matrix = " << determinant;

}

{

int ch,A2[2][2] = {{7, -15} , {13, 5}},AD2[2][2],C2[2][2];

C2[0][0]=A2[1][1]; C2[0][1]=-A2[1][0]; C2[1][0]=-A2[0][1]; C2[1][1]=A2[0][0];

cout<<"\n\nAdjoint of A is :- \n\n";

}

int main()

{

int choice = 0;

cout<<"Press 1 to display the matrix and its transpose"<<endl;

cout<<  "Press 2 to find adjoint and determinant of the matrix"<<endl;

cout<<"Press any other key to exit.";

cin>>choice;

if (choice ==1)

{

ShowMatrix();

showTranspose ( );

}

else if (choice == 2)

{

calculateDeterminant();

}

else

system("pause");

}```

Students kindly share assignment files in relevant subject timely for discussion/solution.