-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex3a.c
executable file
·51 lines (39 loc) · 985 Bytes
/
ex3a.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
#include <stdio.h>
#include <stdlib.h>
#define M 3
#define N 3
void matrice_info(int tab[N][M]){
int nb_pos = 0;
int nb_neg = 0;
int nb_zero = 0;
for (int i = 0; i < N; i++){
for (int j = 0; j < M; j++){
if (tab[i][j] < 0)
nb_neg++;
else if (tab[i][j] > 0)
nb_pos++;
else
nb_zero++;
}
}
printf("Nombre de positifs : %d\n", nb_pos);
printf("Nombre de negatifs : %d\n", nb_neg);
printf("Nombre de zeros : %d\n", nb_zero);
float ratio = (float) nb_zero / ((float) M * (float) N);
if (ratio > 0.8)
printf("matrice creuse");
}
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]);
}
}
matrice_info(tab);
return 0;
}