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 is null defined in c?
Explain the array representation of a binary tree in C.
What is linear search?
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
what type of questions arrive in interview over c programming?
Write the test cases for checking a variable having value in range -10.0 to +10.0?
What does == mean in texting?
What is the difference between #include
Are pointers integer?
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.
Who developed c language and when?
given post order,in order construct the corresponding binary tree
What does != Mean in c?
What is the significance of an algorithm to C programming?
Why is python slower than c?