#include <stdio.h>
FILE *f1;
FILE *f2;
int i=0;
int swc;
int j=0;
int u=0;
int ar[90];
void carica(){
f1=fopen("numeri.txt","r");
fscanf(f1,"%d",&ar[0]);
while(ar[i]!=999){
i++;
fscanf(f1,"%d",&ar[i]);
}
u=i;
fclose(f1);
}
void stampa(){
for(i=0;i<u;i++){
printf("%d\n",ar[i]);
}
}
void scambio(int a, int b){
int comodo;
comodo=ar[a];
ar[a]=ar[b];
ar[b]=comodo;
}
void ordina(){
do{
swc=0;
for(i=0;i<u-1;i++){
j=i+1;
if(ar[i]>ar[j]){
scambio(i,j);
swc=1;
}
}
}
while(swc==1);
}
void copia(){
f2=fopen("ordinati.txt","w");
for(i=0;i<u;i++){
fprintf(f2,"%d\n",ar[i]);
}
fclose(f2);
}
int main()
{
carica();
stampa();
printf("-----------------------\n");
ordina();
stampa();
copia();
}
Commenti
Posta un commento