-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex3b.c
executable file
·59 lines (48 loc) · 1.1 KB
/
ex3b.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>
#define M 3
#define N 3
int matrice_creuse(int matrice[N][M], int vecteur[N*M]){
int i,j;
int k=0;
int nb_zero=0;
for(i=0;i<N;i++){
for(j=0;j<M;j++){
if(matrice[i][j]!=0){
vecteur[k]=matrice[i][j];
k++;
}
else{
nb_zero++;
}
}
}
float ratio = (float) nb_zero / ((float) M * (float) N);
if (ratio > 0.8)
return 1;
return 0;
}
int main ()
{
// Initialisation de la matrice
int tab[N][M];
// saisie de la matrice
for (int i = 0; i < N; i++){
for (int j = 0; j < M; j++){
printf("tab[%d][%d] = ", i, j);
scanf("%d", &tab[i][j]);
}
}
// Initialisation du vecteur
int vecteur[N*M];
// Appel de la fonction matrice_creuse()
int creuse = matrice_creuse(tab, vecteur);
printf("Matrice creuse : %d\n", creuse);
// affichage du vecteur
/*
printf("Vecteur : ");
for(int i=0;i<N*M;i++)
printf("%d ",vecteur[i]);
*/
return 0;
}