IDSA assignment 3
IDSA assignment 3
Department of
Artificial Intelligence and Data Science
Objective: program to represent the sparse matrix using 2D array and perform
transpose and fast transpose on it.
Materials Required:
Computer
IDE that is supported
Visual Studio Code
Procedure:
CODE:
#include<iostream>
using namespace std;
int main(){
int k, l;
int count = 0, m = 0;
cout<< "Enter the nummber of rows :"<<endl;
cin >> k ;
cout<< "Enter the number of columns :"<<endl;
cin >> l ;
int a[k][l];
for (int i=0;i<k;i++){
for (int j=0;j<l;j++){
cout << "Enter the number at "<<i <<" , "<<j << "in the matrix :"<<endl;
cin >> a[i][j];
}
}
cout<<endl;
cout<<"The matrix entered is: "<<endl;
for (int i=0;i<k;i++) {
for(int j=0;j<l;j++){
cout<< a[i][j]<<"\t";
if (j==l-1){
cout<<endl;
}
}
}
cout<<endl;
cout<< "The transpose matrix is :"<<endl;
for (int i=0;i<l;i++) {
for(int j=0;j<k;j++){
cout<< a[j][i]<<"\t";
if (j==k-1){
cout<<endl;
}
}
}
OUTPUT:
Conclusion: In this assignment, we have learned to work with sparse matrices and
represent them on 2D matrix, saving memory and performance. We also learned
to transpose the given matrix increasing our skills in transposing matrix.