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

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
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 comp
ress the sparse matrix by only store non-zero elements. This means storing non-zero elements with triples- (Row, Column, value).
e e e e e e
e 3 e e e e
e e e 6 e e
e e 9 e e e
e e 0 e 12 e
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
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 inte
gers, row number, column number, and data.
Output
輸出原始的矩陣,每個數字後都要跟著一個空白。
Output original matrix. Attach a white space behind each element.
Transcribed Image Text: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 comp ress the sparse matrix by only store non-zero elements. This means storing non-zero elements with triples- (Row, Column, value). e e e e e e e 3 e e e e e e e 6 e e e e 9 e e e e e 0 e 12 e 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 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 inte gers, row number, column number, and data. Output 輸出原始的矩陣,每個數字後都要跟著一個空白。 Output original matrix. Attach a white space behind each element.
Expert Solution
trending now

Trending now

This is a popular 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