answersLogoWhite

0


Best Answer

#include
#include
void main()
{
int a[10][10],b[10][3],r,c,s=0,i,j;
clrscr();
printf("\nenter the order of the sparse matrix");
scanf("%d%d",&r,&c);
printf("\nenter the elements in the sparse matrix(mostly zeroes)");
for(i=0;i{
for(j=0;j{
printf("\n%d row and %d column ",i,j);
scanf("%d",&a[i][j]);
if(a[i][j]!=0)
{
b[s][0]=a[i][j];
b[s][1]=i;
b[s][2]=j;
s++;
}
}
}
printf("\nthe sparse matrix is given by");
printf("\n");
for(i=0;i{
for(j=0;j<3;j++)
{
printf("%d ",b[i][j]);
}
printf("\n");
}
getch();
}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Sparse matrix Program in c language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


C Matrix addition program?

How we can addition Two Matrix plz send coding in C language mahesh dhanotiya astah_mahesh@rediff.com how i can built a square matrix in c,


What are disadvantages of sparse matrix in data structure using c?

what is the disadvantage of sparse matrix?


Program to display multiplication of two matrix?

The matrix multiplication in c language : c program is used to multiply matrices with two dimensional array. This program multiplies two matrices which will be entered by the user.


What is a sparse matrix in c programming?

Sparse matirx can be represented 1-dimensionally, by creating a array of structures, that have members sumc as: Struct RM{int ROW,int COL, int non_zero}; struct RM SM[Number_non_Zeros +1]; then input row,col for each non-zero element of the sparse matrix. if still unclear please fell free to requestion or query on ikit.bbsr@gmail.com, specifying clearly the question in the subject. Chinmaya N. Padhy (IKIT)


Write a c program to determine whether a matrix is singular or not?

A c program is also known as a computer program. A singular matrix has no inverse. An equation to determine this would be a/c=f. &lt;&lt;&gt;&gt; The determinant of a singular matix is zero.


Different parts of c language program?

what are the parts of C language program


A c program to square matrix?

A C program to square matrix is a math problem. In the math problem you write down all the outer boundary values of matrix in a circle, then write down the inner value.


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


A c program to find maximum number in a 3 by 3 matrix?

int matrix[][]; // the matrix to find the max in int max = matrix[0][0]; int r,c; for(r = 0; r &lt; 3; ++r) { for(c = 0; c &lt; 3; ++c) { if(matrix[r][c] &gt; max) { max = matrix[r][c]; } } } // max is now the maximum number in matrix


Program for transpose of sparse matrix?

#include &lt;stdio.h&gt; #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 &lt;= 2 ; i++ ) initsparse ( &amp;s[i] ); create_array ( &amp;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 ( &amp;s[1], s[0] ) ; printf ( "\n\nArray of non-zero elements: " ) ; display_tuple ( s[1] ) ; transpose ( &amp;s[2], s[1] ) ; printf ( "\n\nTranspose of array: " ) ; display_transpose ( s[2] ) ; for ( i = 0 ; i &lt;= 2 ; i++ ) delsparse ( &amp;s[i] ); } /* initialises data members */ void initsparse ( struct sparse *p ) { p -&gt; sp = NULL ; } /* dynamically creates the matrix of size MAX1 x MAX2 */ void create_array ( struct sparse *p ) { int n, i ; p -&gt; sp = ( int * ) malloc ( MAX1 * MAX2 * sizeof ( int ) ) ; for ( i = 0 ; i &lt; MAX1 * MAX2 ; i++ ) { printf ( "Enter element no. %d:", i ) ; scanf ( "%d", &amp;n ) ; * ( p -&gt; sp + i ) = n ; } } /* displays the contents of the matrix */ void display ( struct sparse s ) { int i ; /* traverses the entire matrix */ for ( i = 0 ; i &lt; 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 -&gt; sp ) ; }


Write a C program to find sum of 3 matrices?

matrix