-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPARSE.C
83 lines (69 loc) · 1.35 KB
/
SPARSE.C
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<stdio.h>
#include<stdlib.h>
struct node
{
int num,row,col;
struct node *next;
}*newnd,*spf=NULL,*spl=NULL;
struct node* create(int n,int r, int c)
{
newnd=(struct node*)calloc(1,sizeof(struct node));
newnd->num=n;
newnd->row=r;
newnd->col=c;
newnd->next=NULL;
return newnd;
}
void spar(int a,int b,int c)
{
newnd=create(a,b,c);
if(spf==NULL && spl==NULL)
{
newnd->next=NULL;
spf=spl=newnd;
}
else
{
spl->next=newnd;
spl=spl->next;
spl->next=NULL;
}
}
void printt(struct node *p)
{
printf("\n\nNUM row COL\n");
while(p!=NULL)
{
printf("\n %d %d %d",p->num,p->row,p->col);
p=p->next;
}
}
int main()
{
int i,j;
int ro,co;
printf("Enter no. of rows: ");
scanf("%d",&ro);
printf("Enter no. of columns: ");
scanf("%d",&co);
int arr[ro][co];
for(i=0;i<ro;i++)
{
for(j=0;j<co;j++)
{
printf("Enter value at [%d] [%d]: ",i,j);
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<ro;i++)
{
for(j=0;j<co;j++)
{
if(arr[i][j]!=0)
spar(arr[i][j],i,j);
}
}
printt(spf);
printf("**THANK YOU**");
return 0;
}