WELCOME TO MY BLOG BY SHABEEB.K

C,C++ PROGRAMMING: CONVERT A MATRIX INTO NONE ZERO SPARSE MATRIX

Search This Blog

Friday, 29 November 2013

CONVERT A MATRIX INTO NONE ZERO SPARSE MATRIX


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20][20],r,c,j,i;
clrscr();
cout<<"ENTER ORDER\n";
cin>>r; cin>>c;
cout<<"ENTER ELEMENT\n";
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}

printf("ORIGINAL MATRIX\n");
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
{
printf(" %d ",a[i][j]);
}
}
printf("\n\n\n");
printf("NONE ZERO SPARSE MATRIX\n");

for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(a[i][j]!=0)
{
printf("\n %d  %d  %d ",(i+1),(j+1),a[i][j]);
}
}
}
getch();
}

No comments:

Post a Comment