0% found this document useful (0 votes)
4 views2 pages

SPARS

The document is a C program that performs operations on two sparse matrices. It prompts the user to input the dimensions and elements of two matrices, then displays the non-zero elements of each matrix and computes their addition. The results are printed in a structured format showing the row, column, and value of non-zero entries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

SPARS

The document is a C program that performs operations on two sparse matrices. It prompts the user to input the dimensions and elements of two matrices, then displays the non-zero elements of each matrix and computes their addition. The results are printed in a structured format showing the row, column, and value of non-zero entries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<conio.h>

void main()
{
int a[10][10],b[10][10],c[10][10],row,col,i,j,co=0;
clrscr();
printf("\n Enter No of row and colum for matrix");
scanf("%d%d",&row,&col);
printf("\n Enter First Matrix Element");
for(i=0;i<row;i++)
for(j=0;j<col;j++)
scanf("%d",&a[i][j]);
printf("\n Enter Second Matrix Element");
for(i=0;i<row;i++)
for(j=0;j<col;j++)
scanf("%d",&b[i][j]);

printf("\n First Sparse Matrix");


// printf("\nA\tB\tValue");
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
if(a[i][j]!=0)
{
printf("\n%d\t%d\t%d",(i+1),(j+1),a[i][j]);
}
}
printf("\n Second Sparse Matrix");
// printf("\nA\tB\tValue");
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
if(b[i][j]!=0)
{
printf("\n%d\t%d\t%d",(i+1),(j+1),b[i][j]);
}
}

printf("\n addition of two sparse matrix is");


printf("\nA\tB\tValue\n");
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
co=0;
if(a[i][j]!=0 || b[i][j]!=0)
{
co=1;
c[i][j]=a[i][j]+b[i][j];
printf("%d\t%d\t%d",(i+1),(j+1),c[i][j]);
}
if(co==1)
printf("\n");
}

getch();
}

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