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
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define max(a,b)((a)>(b)?(a):(b))
#define taille 201
void lire(FILE * aLire,double** mat)
{
int i, j ;
for (i = 1; i < taille; i++)
{
for (j =1 ; j < taille; j++)
fscanf(aLire, "%g", & mat[i][j]);
fscanf(aLire, "\n");
}
}
double fh(int i,int j)
{
double **B;
int a=0;
int p,g;
B=(double **) malloc(250*sizeof(double*));
size_t k;
for (k=0; k<250; k++)
{
B[k]=(double*) malloc(250*sizeof(double));
}
FILE * aLire2 = fopen("C:\...fichier.txt", "r");
if(aLire2 == NULL)
{
printf("Le fichier n'existe pas \n");
exit(-1);
}
else
{
lire (aLire2,B);
printf("matrice 2\n");
for (p = 1 ; p <taille; p++)
{
for (g = 1;g < taille; g++)
printf("%8.2g", B[p][g]);
printf("\n");
}
}
fclose(aLire2);
return a;
}
int main(void)
{
double **A;
int i,j;
double d;
int ligne=0, colonne=0;
printf("entrer la ligne\n");
scanf("%d",&ligne);
printf("entrer la colonne\n");
scanf("%d",&colonne);
A=(double **) malloc(ligne*sizeof(double*));
size_t k;
for (k=0; k<ligne; k++)
{
A[k]=(double*) malloc(colonne*sizeof(double));
}
freopen ("file.txt","w",stdout);
FILE * aLire = fopen("C:\\...test.txt", "r") ;
if(aLire == NULL)
{
printf("Le fichier n'existe pas");
}
else
{
lire (aLire, A);
printf("matrice 1\n");
for (i = 1 ; i <taille; i++)
{
for (j = 1;j<taille; j++)
printf("%8.2g", A[i][j]);
printf("\n");
}
d=fh(200,200);
printf("la valeur de d est %g\n",d);
}
fclose (stdout);
return 0;
} |
Partager