Sparsematrix (Mayank Sharma)
Sparsematrix (Mayank Sharma)
while (tempk < count && k[0][tempk] == r && templ < size && l[0][templ] == c)
{
if (k[1][tempk] < l[1][templ])
{
tempk++;
}
else if (l[1][templ] > k[1][tempk])
{
templ++;
}
else
{
sum += k[2][tempk++] * l[2][templ++];
}
}
if (sum != 0)
{
result[0][rcount] = r;
result[1][rcount] = c;
result[2][rcount] = sum;
rcount++;
}
while (lpos < size && l[0][lpos] == c)
{
lpos++;
}
}
while (kpos < count && k[0][kpos] == r)
{
kpos++;
}
}
print(result, rcount);
}
int main()
{
int a[20][20], k[3][100], i, j, m, n, count = 0;
printf("Enter no of rows :");
scanf("%d", &m);
printf("Enter no of coloumns :");
scanf("%d", &n);
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d", &a[i][j]);
if (a[i][j])
{
k[0][count] = i;
k[1][count] = j;
k[2][count] = a[i][j];
count++;
}
}
}
multiply(k, count, m, n);
}
OUTPUT :
Signature :