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
| include <stdio.h>
#include <stdlib.h>
int main ()
{
int val[10];
int i,x,y,temp;
FILE *fich;
if ((fich =fopen("NOMBRES.TXT", "r"))==NULL)
{
printf("%s\n"," Erreur le fichier n'existe pas");
exit (1);
}
for(i=0;i<=9;i++){
fscanf(fich,"%d",&val[i]);
}
for(x=0;x<=8;x++){
for(y=0;y<=8;y++){
if ((val[y])>(val[y+1])){
temp=val[y];
val[y]=val[y+1];
val[y+1]=temp;
}
}
}
if ((fich =fopen("TRI.TXT", "w"))==NULL)
{
printf("%s\n"," probleme d'ouverture de fichier");
exit (1);
}
for(i=0;i<=9;i++){
fprintf(fich,"%d\n",val[i]);
}
fclose(fich);
return 0;
} |
Partager