/* Tanel Toova * 3-2 * Massiivide sorteerimine qsordi abil */ #include #include #include int iMass[100]; int iArv; int x; int y; int compare (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int vordle(const void *arv1, const void *arv2) { return(*(int*)arv1-*(int*)arv2); } void printout() { y=0; for(x=0;x<=99;x++){ printf("%7i",iMass[x]); y++; if(y==10){ printf("\n"); y=0; } } } int main(void) { srand(time(NULL)); for(x=0;x<=99;x++){ iArv = 1 + (int)(10000.0*rand()/(RAND_MAX+1.0)); iMass[x]=iArv; } printout(); qsort(iMass, 100, sizeof (int),vordle); printf("\n"); printout(); }