Write in C Language Description A sparse matrix is a matrix in which most of the elements are zero. Representing a sparse matrix by a 2D array leads to wastage of lots of memory as zeroes in the matrix are of no use in most of the cases. So, we can compress the sparse matrix by only store non-zero elements. This means storing non-zero elements with triples- (Row, Column, value). 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 6 0 0 0 0 9 0 0 0 0 0 0 0 12 0 Here is a 5X6 matrix, there are 4 element non-zero, we using three number represent it 5 6 4 After the three number are (Row, Column, value): row col val 1 1 3 2 3 6 3 2 9 4 4 12 Write a program to read the compressed matrix and print out the original matrix. Input First line consists 3 integers. First and second integers shows the dimensions of original matrix. Third integer k shows number of non-zero elements. Followed k lines are content of the sparse matrix. Each line consists 3 integers, row number, column number, and data.   Output Output original matrix. Attach a white space behind each element.   Sample Input 1  5 6 4 1 1 3 2 3 6 3 2 9 4 4 12 Sample Output 1 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 6 0 0 0 0 9 0 0 0 0 0 0 0 12 0 Expert Answer (doesn't match the sample input. it must match the sample input and output)   Step 1 The program is written in c Step 2   #include int main() {     int a[20][20],n,i,j,k,l;     for(i=0;i<20;i++)     {         for(j=0;j<20;j++)         {             a[i][j]=0;         }     }     printf("Enter the number of elements\n");     scanf("%d",&n);     printf("Enter the elements\n");     for(k=0;k

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write in C Language

Description

A sparse matrix is a matrix in which most of the elements are zero. Representing a sparse matrix by a 2D array leads to wastage of lots of memory as zeroes in the matrix are of no use in most of the cases. So, we can compress the sparse matrix by only store non-zero elements. This means storing non-zero elements with triples- (Row, Column, value).

0 0 0 0 0 0

0 3 0 0 0 0

0 0 0 6 0 0

0 0 9 0 0 0

0 0 0 0 12 0

Here is a 5X6 matrix, there are 4 element non-zero, we using three number represent it

5 6 4

After the three number are (Row, Column, value):

row col val

1 1 3

2 3 6

3 2 9

4 4 12

Write a program to read the compressed matrix and print out the original matrix.

Input

First line consists 3 integers. First and second integers shows the dimensions of original matrix. Third integer k shows number of non-zero elements. Followed k lines are content of the sparse matrix. Each line consists 3 integers, row number, column number, and data.

 

Output

Output original matrix. Attach a white space behind each element.

 

Sample Input 1 

5 6 4
1 1 3
2 3 6
3 2 9
4 4 12

Sample Output 1

0 0 0 0 0 0
0 3 0 0 0 0
0 0 0 6 0 0
0 0 9 0 0 0
0 0 0 0 12 0

Expert Answer (doesn't match the sample input. it must match the sample input and output)

 
Step 1

The program is written in c

Step 2

 

#include <stdio.h>

int main()
{
    int a[20][20],n,i,j,k,l;
    for(i=0;i<20;i++)
    {
        for(j=0;j<20;j++)
        {
            a[i][j]=0;
        }
    }
    printf("Enter the number of elements\n");
    scanf("%d",&n);
    printf("Enter the elements\n");
    for(k=0;k<n;k++)
    {
        scanf("%d",&i);
        scanf("%d",&j);
        scanf("%d",&a[i][j]);
    }
    for(k=0;k<=i;k++)
    {
        for(l=0;l<=j;l++)
        {
            printf("%d ",a[k][l]);
        }
        printf("\n");
    }

    return 0;
}

 

 

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Potential Method of Analysis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education