C: qsort

From AdonaiMedrado.Pro.Br
Revision as of 02:02, 17 April 2009 by Adonaimedrado (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#include <stdio.h>
#include <stdlib.h>
#define TAMANHO_VETOR 10
 
int comparar(const void *a, const void *b)
{
	return *(int *)a-*(int *)b;
}
 
int main(void)
{
	int i, v[TAMANHO_VETOR];
	for(i=0;i<TAMANHO_VETOR;i++)
		scanf("%d",v+i);
 
	qsort(v,TAMANHO_VETOR,sizeof(int),comparar);
 
	for(i=0;i<TAMANHO_VETOR;i++)
		printf("%d ",*(v+i));
	printf("\n");
 
	return 0;
}