# Tag: Sparse matrix

## Sparse Matrix representation for polynomials

Sparse Matrix representation for polynomials Program to represent two polynomials using Sparse Matrix representation using arrays, compute sum of two polynomials and represent the result using sparse matrix: /* Sparse Matrix Representation for Polynomials */ #include <stdio.h> #include <stdlib.h> #define MAX 15 int main(){ int poly1[MAX][MAX]={0},poly2[MAX][MAX]={0},poly3[MAX][MAX]={0}; int i,j,k,m,n,nrows,nrows1,nrows2,nrows3,ncols,ct=0,ct1=0,ct2=0; int spmat1[MAX][MAX]={0},spmat2[MAX][MAX]={0},spmat3[MAX][MAX]={0}; int deg,deg1,deg2,deg3; printf(“nEnter degree of […]

## Program to represent two polynomials using arrays and compute their sum

Sparse Polynomial representation and addition Program to represent two polynomials using arrays and compute their sum /* Representation of Polynomials using arrays */ /* Addition of two Polynomials */ #include <stdio.h> #define MAX 10 int main(){ int poly1[MAX]={0},poly2[MAX]={0},poly3[MAX]={0}; int i,deg1,deg2,deg3; printf(“nEnter degree of first polynomial?”); scanf(“%d”,&deg1); printf(“nEnter degree of second polynomial?”); scanf(“%d”,&deg2); printf(“nFor first polynomial:”); […]

## Sparse Polynomial representation and addition

Sparse Polynomial representation and addition: Polynomial is an expression which is composed of terms, wherein terms are composed of coefficient and exponent.  An example of a polynomial is: 4×3+5×2+6x+9.  This polynomial is composed of four terms with the following sets of coefficient and exponent – {(4,3), (5,2), (6,1), (9,0)}.  Thus representation of a polynomial using […]

## Program to represent Sparse Matrix using singly linked list (One dimensional list)

Sparse Matrix representation using singly Linked List: /* Sparse Matrix representation using linked list */ #include <stdio.h> #include <stdlib.h> typedef struct list{ int rows, cols, value; struct list *next; }list; list *create(){ list *temp = (list *)malloc(sizeof(list)); if(temp==NULL){ printf(“nMemory Allocation Error !”); exit(1); } return temp; } list *makenode(int r, int c, int val){ list […]

## Program to represent Sparse Matrix using arrays

Program to represent Sparse Matrix using arrays: /* Sparse Matrix representation using arrays */ #include <stdio.h> #include <stdlib.h> #define MAX 15 int main(){ int arr,i,j,m,n,nrows,ncols,ct=0; int sparse_matrix[MAX][MAX]; for(i=0;i<3;i++){ printf(“nEnter values for row %d?”,i+1); for(j=0;j<4;j++){ scanf(“%d”,&arr[i][j]); if(arr[i][j] != 0) ct++; } } nrows = ct+1; ncols = 3; sparse_matrix = 3; sparse_matrix = 4; sparse_matrix = […]