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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define max(a,b)((a)>(b)?(a):(b))
typedef int Matrice [100][100];
typedef int rempduree[100][100];
rempduree red;
void lire(FILE * aLire, Matrice mat)
{
int i, j ;
for (i = 1; i <11; i++)
{
for (j =1 ; j <11; j++)
fscanf(aLire, "%d", & mat[i] [j]);
fscanf(aLire, "\n");
}
}
void remplir_matrice_duree(rempduree red,Matrice m)
{
int i,j,C[100];
int nb;
printf("matrice donnee\n");
for (i = 1 ; i <11; i++)
{
for (j = 1;j<11; j++)
printf("%5.2d", m[i][j]);
printf("\n");
}
//printf("salut\n");
for(i=1;i<11;i++)
{ j=1;
while ((m[i][j]==0)&(j<=i))
{
j++;
}
C[i]=j;
}
for(i=1;i<11;i++)
{
printf("%d\n",C[i]);
}
for(j=1;j<11;j++)
{
for(i=j;i<11;i++)
if(C[i]<=j)
{
if (i>j)
{
nb=4*(j-max(C[i],C[j]))+2;
red[i][j]=nb;
}
else
{
if (i==j)
nb=4*(j-C[j]);
red[j][j]=nb;
//printf("%d\n",red[j][j]);
}
}
}
for (i = 1 ; i <11; i++)
{
for (j = 1;j<11; j++)
printf("%5.2d", red[i][j]);
printf("\n");
}
}
void ecrire(rempduree red)
{
int i,j;
for(j=1;j<12;j++)
{
for(i=j;i<12;i++)
printf("%d",red[i][j]);
printf("\n");
}
}
void writeMatrixtoFile(Matrice mat)
{
int i,j;
for (i = 1 ; i <11; i++)
{
for (j = 1;j<11; j++)
printf("%5.2d", mat[i][j]);
printf("\n");
}
}
int duree (int i, int j)
{
int a;
rempduree red;
if(i>j)
{
a=red[i][j];
}
else
if (i==j)
{
a=red[j][j];
}
return a;
}
int main(void)
{
Matrice A;
int m, n;
int d;
rempduree redtab;
/* ouvrir le fichier test sur le disque réseau pour la lecture */
FILE * aLire = fopen("C: ......\\test.txt", "r") ;
if(aLire == NULL)
{
printf("Le fichier n'existe pas");
}
else
{
fscanf(aLire,"%d %d\n", &m, &n);
lire (aLire, A);
writeMatrixtoFile(A);
remplir_matrice_duree(redtab,A);
d=duree(9,9);
printf("valeur de d est %d\n",d);
// ecrire(redtab);
}
return 0;
} |
Partager