Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions hard2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <stdio.h>
#define MAX 20

void read_matrix(int a[10][10], int row, int column);
void print_sparse(int b[MAX][3]);
void create_sparse(int a[10][10], int row, int column, int b[MAX][3]);

int main()
{
int a[10][10], b[MAX][3], row, column;
printf("\nEnter the size of matrix (rows, columns): ");
scanf("%d%d", &row, &column);

read_matrix(a, row, column);
create_sparse(a, row, column, b);
print_sparse(b);
return 0;
}

void read_matrix(int a[10][10], int row, int column)
{
int i, j;
printf("\nEnter elements of matrix\n");
for (i = 0; i < row; i++)
{
for (j = 0; j < column; j++)
{
printf("[%d][%d]: ", i, j);
scanf("%d", &a[i][j]);
}
}
}

void create_sparse(int a[10][10], int row, int column, int b[MAX][3])
{
int i, j, k;
k = 1;
b[0][0] = row;
b[0][1] = column;
for (i = 0; i < row; i++)
{
for (j = 0; j < column; j++)
{
if (a[i][j] != 0)
{
b[k][0] = i;
b[k][1] = j;
b[k][2] = a[i][j];
k++;
}
}
b[0][2] = k - 1;
}
}

void print_sparse(int b[MAX][3])
{
int i, column;
column = b[0][2];
printf("\nSparse form - list of 3 triples\n\n");
for (i = 0; i <= column; i++)
{
printf("%d\t%d\t%d\n", b[i][0], b[i][1], b[i][2]);
}
}
8 changes: 8 additions & 0 deletions questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ v) 55555
22
1

vi)
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15


4. Program to count no of vowels, consonant, digits and white spaces in a string.

5. Program to multiply 2 Matrices created dynamically.
Expand Down