0% found this document useful (0 votes)
6 views6 pages

IDSA assignment 3

The document outlines an assignment for a student named Aditya Sirsat at Vishwakarma Institute of Information Technology, focusing on representing a sparse matrix using a 2D array and performing transpose operations. It includes a detailed procedure with C++ code for inputting a matrix, counting non-zero elements, and displaying the sparse matrix. The conclusion emphasizes the learning outcomes related to sparse matrices and matrix transposition.

Uploaded by

adityasirsat1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

IDSA assignment 3

The document outlines an assignment for a student named Aditya Sirsat at Vishwakarma Institute of Information Technology, focusing on representing a sparse matrix using a 2D array and performing transpose operations. It includes a detailed procedure with C++ code for inputting a matrix, counting non-zero elements, and displaying the sparse matrix. The conclusion emphasizes the learning outcomes related to sparse matrices and matrix transposition.

Uploaded by

adityasirsat1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Bansilal Ramnath Agarwal Charitable Trust’s

Vishwakarma Institute of Information


Technology

Department of
Artificial Intelligence and Data Science

Student Name: Aditya Sirsat

Class: F.Y. B. Tech Division: B (B2) Roll No.: 107235

Semester: 2nd Semester Academic Year: 2023-24

Subject Name & Code: IDSA


Assignment No: 3
Data Collected based on different parameters for analysis represented in
matrix given below.
00200
00005
03000
70000
Program to represent this sparse matrix using 2D Array and perform
transpose and fast transpose on it.

Date of Performance: Date of Submission:


Aim: Data collected based on different parameters for analysis represented in
matrix given below.

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;
}
}
}

//firdt count the non-zero elements in the user defined matrix.


for(int i = 0; i<k; i++){
for(int j = 0; j<l;j++){
if( a[i][j] != 0 ){
count++;}
}
}
cout<<endl;
cout<<"The Number of non-zero elements is: "<< count<< endl;
int b[count][3];
for (int i=0;i<k;i++) {
for(int j=0;j<l;j++){
if (a[i][j]!=0){
b[m][0]=i;
b[m][1]=j;
b[m][2]=a[i][j];
m++;}
}
}
cout<<endl;
cout<< "The sparse matrix is :" << endl;
for(int i = 0; i<count; i++){
for(int j = 0; j<3; j++){
cout<<b[i][j]<<"\t";
if(j==2){
cout<<endl; }
}}
return 0;}

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy