Programme to check Sparse matrix

Programme to check Sparse matrix

/* wap to print sparse matrix */

#include<stdio.h>
#include<conio.h>
#define n 3
void main()
{
int i,j,a[n][n],count=0;
clrscr();
printf("Enter elements of matrix\n");
for(i=0;i<n;i++)
    {
    for(j=0;j<n;j++)
    {
        scanf("%d",&a[i][j]);
    }
}
printf("You Entered matrix:\n");

for(i=0;i<n;i++)
    {
    for(j=0;j<n;j++)
    {
        printf("%d\t",a[i][j]);
    }
    printf("\n");
}
for(i=0;i<n;i++)
{
    for(j=0;j<n;j++)
    {
    if(a[i][j]==0)
        {
        count=count+1;
        }
    }
}
if(count>((n*n/2)))
printf("It is a sparse matrix:\n");
else
printf("Not a sparse matrix");
getch();
}












SHARE

Ramandeep Singh

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 $type={blogger}:

Post a Comment