write a C Program to find addition of two sparse matrices

itstudentjunction


Write a C Program to find addition of sparse matrix


WHAT IS A SPARSE MATRIX:

A sparse matrix is a matrix having maximum no, of elements as zero

example of sparse matrix

1 0 0 0
0 0 2 0
0 0 0 0

write a c program to add sparse matrices


write a c program to find addition of sparse matrices or add sparse matrices or print sparse matrices


#include < stdio.h >
#include < conio.h >
void main()
{
int sp1[2][3],sp2[2][3],sp3[2][3];
clrscr();
printf("\nTo find addition of sparse matrices\n");
printf("\nEnter first sparse matrix");
read_sparse(sp1);
printf("\nEnter second sparse matrix");
read_sparse(sp2);
printf("\nEnter third sparse matrix");
read_sparse(sp3); xzc
printf("\nFirst sparse matrix is");
print_sparse(sp1);
printf("\nSecond sparse matrix is");
print_sparse(sp2);
printf("\nThird sparse matrix is");
print_sparse(sp3);

printf("\n addition of sparse matrices is\n", addition_sparse(sp1,sp2,sp3));
} // end of main

// read sparse matrix
int read_sparse(int sp[2][3]){
int i,j,k,t;
printf("\nEnter the elements of sparse matrix \n");
k=1;
for(i=0;i < 2;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&t);
if( t != 0 )
{
sp[i][j] = t;

} // if
j++
}; // for
i++;
}
} // end of read sparse matrix


// print sparse matrix
int print_sparse(int sp[2][3]){
printf("\n r \t c \t element")
int i=0,j=0;
for(i=0;i < 2;i++)
{
for(j=0;j<3;j++)
{
if (sp[i][j] !=0)
{
printf("\n %d \t %d \t %d \n" i, j , sp[i][j]);

} // end of print sparse

// add sparse matrices

int addition_sparse(sp1,sp2,sp3)
{
int SPARSE_RESULT[2][3];
int i,j;
for(i=0;i < 2;i++)
{
for(j=0;j<3;j++)
{
SPARSE_RESULT[i][j]= sp1[i][j] + sp2[i][j] + sp3[i][j]
}
}
print_sparse(SPARSE_RESULT);
// end of sparse addition
}

output:

To find addition of sparse matrices

Enter first sparse matrix
Enter the elements of sparse matrix
1 0 0 0 0 1
Enter second sparse matrix
Enter the elements of sparse matrix
0 0 0 1 0 3
Enter third sparse matrix
Enter the elements of sparse matrix
0 2 0 1 0 0


First sparse matrix is:
i j element
0 0 1
2 1 1

Second sparse matrix is:
i j element
1 1 1
2 1 3

Third sparse matrix is:
i j element
0 1 2
1 1 1

addition of sparse matrices is
i j element
0 0 1
0 1 2
1 1 2
2 1 4


Other matrices programs:



write a c program for addition of two matrices or add two matices
write a c pprogram to show multiplication of two matrices or multiply two matrices

write a c program to find transpose of a matrix

write a c program to find inverse of matrix

write a c program to find lower triangle of a matrix
write a c program to find upper triangle of a matrix
write a c program to implement sparse matrix
write a c program to find addition sparse matrix or add sparse matrices

write a c program to multiply two sparse matrices or find multiplication of sparse matrices



Custom Search


write a c program to find check calculate print show SI write a c program to find check calculate print show CI write a c program to find check calculate print show factorial number write a c program to find check print show even / odd write a c program to find check print show perfect number or not write a c program to find check print show prime number or not write a c program to find check calculate print show factors of numberwrite a c program to find check print show prime factors write a c program to find check calculate print show armstrong number or notwrite a c program to find check calculate print show amicable pair write a c program to find check calculate print show sum of n numbers write a c program to find check calculate print show average of n numbers write a c program to find check calculate print show largest of two numbers write a c program to find check calculate print show largest of n numbers write a c program to find check calculate print show LCM of two numberswrite a c program to find check calculate print show GCD of two numberswrite a c program to find check calculate print show sum of n numbers write a c program to find check calculate print show numbers in word write a c program to find check calculate print show pascal Triangle find roots write a c program to find check calculate print show addition subtraction of complex numbers write a c program to find check calculate print show multiplication of complex numbers write a c program to find check calculate print show numbers pyramid write a c program to find check calculate print show decimal to binary write a c program to find check calculate print show decimal to octal write a c program to find check calculate print show decimal to hexadecimal sum of digits towers of hannoi write a c program to find check calculate print show palindrome number write a c program to find check calculate print show strong number or not biggest of three largest & smallest values in array combinationsno.of digits permutations prime numbers power value reverse number smallest number in array sum of Digits Floyd’s Triangle even or odd swap numbers implementing function implementing function Function with no arguments and a return value function with no arguments and no return value addition of two matrices multiplication of two matrices transpose of matrix inverse of matrix lower triangle upper triangle sparse matrix addition two sparse matrix multiply sparse matrix SI using macros max min values gcd using recurrsion fibonacci numbers factorial using recurrsion sum of factorial series reverse number sizes data types automatic variable scope external variable scope static variable scope register variable scope employee data reverse string strrev reverse string pointers reverse string arrays string length strlen string length arrays string length pointers concatinate strings strCat concatinate strings arrays convert to lowercase convert to uppercase convert to lowercase check substring first occurance of character count words count vowels compare two strings arrays compare strings pointers compare strings strcmp palindrome string substring position string combinations acromatic string rain drop character copy file student records in file line styles fill styles font styles escape operators B-TREE MULTIWAY TREE AVL TREE SPLAY TREE RED BLACK TREE HASHING PRIORITY QUEUE DIJKSTRA'S ALGORITHM KNAPSACK PROBLEM ADJACENCY LIST DEPTH FIRST SEARCH MINIMAL SPANNINGTREE KRUSKAL'S ALGORITHM MINIMAL SPANNING TREE PRIMS ALGORITHM BREADTH FIRST SEARCH LINEAR SEARCH POINTERS BINARY SEARCH POINTERS LINEAR SEARCH ARRAYS BINARY SEARCH ARRAYS BUBBLE SORTARRAYS MERGE SORT ARRAYS SELECTION SORT ARRAYS INSERTION SORT ARRAYS TOPOLOGICAL SORT ARRAYS HEAP SORT ARRAYS HEAP SORT POINTERS BUBBLE SORT arrays MATRIX MULTIPLICATION TRANSPOSE OF MATRIX LEXICOGRAPHIC ORDER SUBSTRING its POSITION CONCATENATE STRINGS STUDENT INFORMATION MULTIPLY SPARCE MATRICES COUNT STRINGS LINKED LIST POINTERS REVERSE STRING PREFIX TO POSTFIX SINGLE LINKED LIST COUNT NODES LINEAR LINKED LIST CIRCULAR LINKED LIST CONCATENATE LISTS PRINT LIST ELEMENTS COMMON IN TWO LISTS SORT LIST CIRCULAR LINKED LIST REVERSE LINKED LIST SHOW POLYNOMIAL ADD POLYNOMIALS STACK ARRAYS STACk (pointers) MULTIPLE STACK EXPRESSION TREE TRAVERSALS INFIX TO POSTFIX QUEUE ARRAYS QUEUE POINTERS CIRCULAR QUEUE ARRAYS QUEUE USING ARRAYS REVERSE A QUEUE BINARY TREE BINARY TREE TRAVERSALS LEAVES OF BINARY TREE first occurrence of substring last occurrence of substring check substring C Programs Data structures Programs in c Data structures Programs in c++ Computer Graphics Programs Unix commands Linux commands HTML programmingC++ programs,Data structures Algorithms, Java Programs UML Diagrams Assembly Language Programs DBMS j2ee programming c tutorials c++ tutorials java tutorials Data structures tutorials DBMS tutorials