Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

qsort,为什么我的总是Runtime Error呢?大家帮忙看看,谢谢!

Posted by sunkehappy at 2009-03-01 11:07:10 on Problem 2388
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b)
{
		return *(long int *)a - *(long int *)b;
}
int main( void )
{
    long i, j, *cow, sets ;
    scanf("%d", &sets ) ;
    cow = ( long*)malloc(sizeof(long) );
    for( i = 0; i < sets; ++i )
     	scanf("%d", &cow[i] ) ;
    qsort( cow, sets, sizeof(long int), cmp) ;
    printf("%ld\n", cow[sets/2] ) ;
    return 0 ;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator