how to generate sparse matrix in c

Answer Posted / it career point

//program to 3-tuple representation
#include<stdio.>
#include<conio.h>
void main()
{
int a[5][5],row,columns,i,j;
printf(Ënter the order of the matrix.(5*5)");
scanf("%d%d",&row,&columns);
printf("Enter the element of the matrix\n");
for(i=0;i<row;i++)
for(j=0;j<columns;j++)
{
scanf("%d", &a[i][j]);
}
printf("3-tuple representation");
for(i=0;i<row;i++)
for(j=0;j<column;j++)
{
if(a[i][j]!=0)
{
printf("%d %d %d", (i+1),(j+1),a[i][j]);
}
}

getch();
}

Is This Answer Correct ?    41 Yes 42 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many bytes is a struct in c?

907


How do you declare a variable that will hold string values?

927


What is static memory allocation?

848


What is a char c?

804


How many main () function we can have in a project?

881


What is logical error?

855


Can 'this' pointer by used in the constructor?

824


How do you initialize pointer variables?

809


write an algorithm to display a square matrix.

2441


Explain what are global variables and explain how do you declare them?

845


What is action and transformation in spark?

834


FILE PROGRAMMING

1994


What are structures and unions? State differencves between them.

856


how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software

3053


Which control loop is recommended if you have to execute set of statements for fixed number of times?

1097