Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
733 B
1
Indexable
Never
#include<stdio.h>
int sp[10][3];
int k=0, a[10][10];
void sparse(int m, int n) {
    int i, j;

    for (i = 0; i < m; i++) {
        for (j = 0; j < n; j++) {
            if (a[i][j] != 0) {
                sp[k][0] = i;
                sp[k][1] = j;
                sp[k++][2] = a[i][j];
            }
        }
    }

    for (i = 0; i < k; i++)
        printf("%d\t%d\t%d\n", sp[i][0], sp[i][1], sp[i][2]);
}


void main(){
int m, n, j, i;
clrscr();
printf("Enter the Row size: \n");
scanf("%d", &m);
printf("Enter the Column size: \n");
scanf("%d", &n);
for(i=0;i<m;i++)
	for(j=0;j<n;j++){
		printf("Enter the values of a[%d][%d]\n", i, j);
		scanf("%d", &a[i][j]);
	}
sparse(m, n);
getch();
}
Leave a Comment