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
Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
Explain modulus operator. What are the restrictions of a modulus operator?
Find MAXIMUM of three distinct integers using a single C statement
What are file streams?
Write a program to check whether a number is prime or not using c?
When is the “void” keyword used in a function?
What is structure padding in c?
write a c program to find the sum of five entered numbers using an array named number
What is the use of f in c?
where are auto variables stored? What are the characteristics of an auto variable?
How do you search data in a data file using random access method?
Write a program to print fibonacci series using recursion?
"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks
What are the disadvantages of external storage class?
Explain what are reserved words?