answersLogoWhite

0

#include <stdio.h>

#define MAX1 3

#define MAX2 3

struct sparse

{

int *sp ;

int row ;

} ;

void initsparse ( struct sparse * ) ;

void create_array ( struct sparse * ) ;

void display ( struct sparse ) ;

int count ( struct sparse ) ;

void create_tuple ( struct sparse *, struct sparse ) ;

void display_tuple ( struct sparse ) ;

void transpose ( struct sparse *, struct sparse ) ;

void display_transpose ( struct sparse ) ;

void delsparse ( struct sparse * ) ;

void main( )

{

struct sparse s[3] ;

int c, i ;

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

initsparse ( &s[i] );

create_array ( &s[0] ) ;

printf ( "\nElements in Sparse Matrix: " ) ;

display ( s[0] ) ;

c = count ( s[0] ) ;

printf ( "\n\nNumber of non-zero elements: %d", c ) ;

create_tuple ( &s[1], s[0] ) ;

printf ( "\n\nArray of non-zero elements: " ) ;

display_tuple ( s[1] ) ;

transpose ( &s[2], s[1] ) ;

printf ( "\n\nTranspose of array: " ) ;

display_transpose ( s[2] ) ;

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

delsparse ( &s[i] );

}

/* initialises data members */

void initsparse ( struct sparse *p )

{

p -> sp = NULL ;

}

/* dynamically creates the matrix of size MAX1 x MAX2 */

void create_array ( struct sparse *p )

{

int n, i ;

p -> sp = ( int * ) malloc ( MAX1 * MAX2 * sizeof ( int ) ) ;

for ( i = 0 ; i < MAX1 * MAX2 ; i++ )

{

printf ( "Enter element no. %d:", i ) ;

scanf ( "%d", &n ) ;

* ( p -> sp + i ) = n ;

}

}

/* displays the contents of the matrix */

void display ( struct sparse s )

{

int i ;

/* traverses the entire matrix */

for ( i = 0 ; i < MAX1 * MAX2 ; i++ )

{

/* positions the cursor to the new line for every new row */

if ( i % MAX2 0 )

printf ( "\n" ) ;

printf ( "%d\t", * ( p.sp + i ) ) ;

}

}

/* deallocates memory */

void delsparse ( struct sparse *p )

{

free ( p -> sp ) ;

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What is transpose of the sparse matrix?

Another sparse matrix.


What is a fast-transpose algorithm for sparse matrices?

A fast-transpose is a computer algorithm that quickly transposes a sparse matrix using a relatively small amount of memory. Using arrays normally to record a sparse matrix uses up a lot of memory since many of the matrix's values are zero. In addition, using the normal transpose algorithm to transpose this matrix will take O(cols*elements) amount of time. The fast-transpose algorithm only uses a little memory to record the matrix and takes only O(cols+elements) amount of time, which is efficient considering the number of elements equals cols*rows.


Is it true that the transpose of the transpose of a matrix is the original matrix?

yes, it is true that the transpose of the transpose of a matrix is the original matrix


Write a program to print the sum of a sparse matrix?

This is a directive, not a question.


What is a sparse matrix?

A sparse matrix is a matrix in which most of the elements are zero.


Transpose matrix in data structure?

DataStructure-Program to transpose a sparse matrix.#include #include #include #define MAX1 3#define MAX2 3struct sparse{int *sp ;int row ;} ;void initsparse ( struct sparse * ) ;void create_array ( struct sparse * ) ;void display ( struct sparse ) ;int count ( struct sparse ) ;void create_tuple ( struct sparse *, struct sparse ) ;void display_tuple ( struct sparse ) ;void transpose ( struct sparse *, struct sparse ) ;void display_transpose ( struct sparse ) ;void delsparse ( struct sparse * ) ;void main( ){struct sparse s[3] ;int c, i ;for ( i = 0 ; i sp = ( int * ) malloc ( MAX1 * MAX2 * sizeof ( int ) ) ;for ( i = 0 ; i < MAX1 * MAX2 ; i++ ){printf ( "Enter element no. %d:", i ) ;scanf ( "%d", &n ) ;* ( p -> sp + i ) = n ;}}/* displays the contents of the matrix */void display ( struct sparse s ){int i ;/* traverses the entire matrix */for ( i = 0 ; i < MAX1 * MAX2 ; i++ ){/* positions the cursor to the new line for every new row */if ( i % MAX2 0 )printf ( "\n" ) ;printf ( "%d\t", * ( p.sp + i ) ) ;}}/* deallocates memory */void delsparse ( struct sparse *p ){free ( p -> sp ) ;}


What is the definition of transpose in regards to a matrix?

The Transpose of a MatrixThe matrix of order n x m obtained by interchanging the rows and columns of the m X n matrix, A, is called the transpose of A and is denoted by A' or AT.


What is a symmetric matrix?

a square matrix that is equal to its transpose


How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


How to identify Sparse matrix?

A sparse matrix is one which normally contains a large proportion of elements whose value is 0. There is no exact proportion at which a matrix becomes sparse.


What is matrix programming in C programming?

C Examples on Matrix OperationsA matrix is a rectangular array of numbers or symbols arranged in rows and columns. The following section contains a list of C programs which perform the operations of Addition, Subtraction and Multiplication on the 2 matrices. The section also deals with evaluating the transpose of a given matrix. The transpose of a matrix is the interchange of rows and columns.The section also has programs on finding the trace of 2 matrices, calculating the sum and difference of two matrices. It also has a C program which is used to perform multiplication of a matrix using recursion.C Program to Calculate the Addition or Subtraction & Trace of 2 MatricesC Program to Find the Transpose of a given MatrixC Program to Compute the Product of Two MatricesC Program to Calculate the Sum & Difference of the MatricesC Program to Perform Matrix Multiplication using Recursion


Wap to build a sparse matrix as an arraywrite functions to check if the sparse matrix is a square diagonal or lower triangular or upper triagular or tridiagonal matrix?

write a programe to build a sparse matrix as an array. write function to check if the sparse matrix is a square, diagonal,lower triangular, upper triangular or tridiagonal matrix