ASSIGNMENT 12 CS 392 : TCPTUTOR

10
176

PROBLEM STATEMENT

Write a C program to express a Sparse Matrix in its 3-tuple form. Explain efficient use of memory in tuple representation. (Take a 5×5 matrix with 3 nonzero elements)

ALGORITHMS

ALGORITHM TO SPARSIFY A 5×5 MATRIX :

a: Matrix to be sparsified
b1: New matrix formed after sparsification of matrix a
bi: index of row of b1
bj: index of column of b1
c1: temporary matrix for passing of value of matrix a
i: index of row of matrix a
j: index of column of matrix a
k: temporary variable for passing index of row of matrix a
l: temporary variable for passing index of column of matrix a

Initialise a[5][5],b1[3][3],bi=0 and bj=0
MAIN()
Step 1: SET i=0 while i<5 repeat step 2
Step 2: SET j=0 while j<5 repeat step 3
Step 3: IF a[i][j]!=0
SPARSIFY(a,i,j)
[End of IF]
[End of loop]
[End of loop]
Step 4: Exit

SPARSIFY(int c1[5][5], int k, int l)
Step 1: SET b1[bi][0]=(k+1)
Step 2: SET b1[bi][1]=(l+1)
Step 3: SET b1[bi][2]=c1[k][l]
Step 4: SET bi=bi+1;
Step 5: STOP

SOURCE CODE

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int b1[3][3],bi=0,bj=0;
void sparsify(int c1[5][5], int k, int l)
{
b1[bi][0]=(k+1);
b1[bi][1]=(l+1);
b1[bi][2]=c1[k][l];
bi++;
}
int main()
{
system(“cls”);
int a[5][5]={
{0,0,0,0,0},
{0,2,0,0,0},
{0,0,0,6,0},
{0,0,0,0,0},
{0,0,0,8,0}};
int i,j;
printf(“row\tcolumn\tvalue\n”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i][j]!=0)
sparsify(a,i,j);
}
}
for(bi=0;bi<3;bi++)
{
for(bj=0;bj<3;bj++)
{
printf(“%d\t”,b1[bi][bj]);
}
printf(“\n”);
}
return 0;
}

OUTPUT

row        column    value
2            2             2
3            4             6
5            4             8

***************************

NOTE: Initialize matrix yourself and write output accordingly.

10 COMMENTS

  1. 9合1升級保護,提升全面防護!!! 相比之前四合一的疫苗只能預防四種hpv病毒,70的相關癌症。 九合一可以預防9種hpv病毒,可預防高達90以上的子宮頸癌、外陰癌、陰道癌和肛門癌及癌前病變等。 HPV9合1子宮頸癌疫苗 Gardasil 功效 100 預防高危致癌的 HPV 16、18、31、33、45、52 及 58 型號 (可減低 90 患子宮頸癌、、90-95 肛門癌、85-90 外陰癌、80-85 陰道癌及相關癌前病變的風險) 100 減低引致生殖器官濕疣 (俗稱「椰菜花」) 的 HPV 6、11 型的感染 (可減低超過 90 患生殖器官濕疣的風險) 男性方面,能減低患上肛門癌、生殖器官濕疣 (俗稱「椰菜花」) 及傳播 HPV 病毒的風險 注射位置紅腫及痛、輕微發燒和頭痛,至今未有嚴重副作用記錄

  2. Venus Viva™對所有皮膚類型都是安全的,並使用革命性的Nano Fractional Radio Frequency™(納米點陣射頻™)和Smart Scan™(智能掃描™)技術,通過選擇性真皮加熱,從而提供優異的治療效果。使用Nano Fractional RF™將能量透過表皮傳遞至真皮,從而產生熱量,並啟動膚膚的生理機制,重建膠原蛋白及刺激纖維母細胞,最終刺激導致組織重塑。功效:✔改善膚質✔肌膚緊緻✔減淡妊娠紋✔痤瘡及暗瘡疤痕✔減淡細紋及皺紋✔面部肌膚賦活再生 適合面部及頸部

LEAVE A REPLY

Please enter your comment!
Please enter your name here