Cod sursa(job #1438131)

Utilizator alexandrionUNIBUC Marcu Alexandru alexandrion Data 19 mai 2015 00:59:44
Problema Sortare prin comparare Scor 100
Compilator c Status done
Runda Arhiva educationala Marime 0.58 kb
#include <stdio.h>
#include <stdlib.h>

FILE *f , *g;
//int (*p) (long int ,long int);
int cmp(const void *a,const void *b)
{ return *((long int*)a)- *((long int*)b);
}

int main()
{ long int *v,n,i;
f=fopen("algsort.in","r");
g=fopen("algsort.out","w");
//printf(" n=");
fscanf(f,"%ld",&n);
v= (int*)malloc(n*sizeof(long int));
for(i=0; i<n ; i++)
fscanf(f,"%ld",&v[i]);
//for(i=0;i<n;i++)
//v[i]=rand()%100;
//for(i=0;i<n;i++)
//fprintf(f,"%d ",v[i]);
qsort(v,n,sizeof(long int),cmp);
//fprintf("\n\n\n\n");
for(i=0;i<n;i++)
fprintf(g,"%ld ",v[i]);

    return 0;
}