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
Write a program to reverse a given number in c?
Is it better to bitshift a value than to multiply by 2?
In a header file whether functions are declared or defined?
What are control structures? What are the different types?
i have a written test for microland please give me test pattern
What are the 3 types of structures?
Write a program to show the change in position of a cursor using c
What does. int *x[](); means ?
which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;
Which operators cannot be overloaded a) Sizeof b) .* c) :: d) all of the above
main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none
What is c language in simple words?
Explain the red-black trees?
How do you override a defined macro?
Why isnt there a numbered, multi-level break statement to break out