Answer Posted / d. prashant
/* Program of sparse matrix for 3-tuple method using array*/
#include
#define srow 50
#define mrow 20
#define mcolumn 20
main()
{
int mat[mrow][mcolumn],sparse[srow][3];
int i,j,nzero=0,mr,mc,sr,s;
printf("Enter number of rows : ");
scanf("%d",&mr);
printf("Enter number of columns : ");
scanf("%d",&mc);
for(i=0;i for(j=0;j {
printf("Enter element for row %d,column %d : ",i+1,j+1);
scanf("%d",&mat[i][j]);
}
printf("Entered matrix is : \n");
for(i=0;i {
for(j=0;j {
printf("%6d",mat[i][j]);
if(mat[i][j]!=0)
nzero++;
}
printf("\n");
}
sr=nzero+1;
sparse[0][0]=mr;
sparse[0][1]=mc;
sparse[0][2]=nzero;
s=1;
for(i=0;i for(j=0;j {
if(mat[i][j]!=0)
{
sparse[s][0]=i+1;
sparse[s][1]=j+1;
sparse[s][2]=mat [i][j];
s++;
}
}
printf("Sparse matrix is :\n");
for(i=0;i {
for(j=0;j<3;j++)
printf("%5d",sparse[i][j]);
printf("\n");
}
}/*End of main()*/
Is This Answer Correct ? | 57 Yes | 50 No |
Post New Answer View All Answers
How can I call a function with an argument list built up at run time?
What is wild pointer in c with example?
Which is an example of a structural homology?
Explain how do you sort filenames in a directory?
Write a program to swap two numbers without using third variable in c?
Why main is not a keyword in c?
Can you add pointers together? Why would you?
What is the auto keyword good for?
What is an expression?
Are there namespaces in c?
What is register variable in c language?
how do you programme Carrier Sense Multiple Access
In c programming language, how many parameters can be passed to a function ?
Should I learn data structures in c or python?
we need to calculating INCOME TAX for the person. The INCOME TAX is as follows:- First $10000/- of income : 4% tax Next $10000/- of income : 8% tax Next $10000/- of income : 11.5% tax above $10, 00,00/- : 15% tax What is the Solution of this Question ?