Chef and Apple Trees(December Challenge)

This code gives a runtime error.What is the problem with this code?

#include<stdio.h>
#include<stdlib.h>
int cmpfunc(const void a,const void b)
{
return(
(int
)a-(int)b);
}
void main()
{
int t,j;
scanf("%d\n",&t);
for(j=0;j<t;j++)
{
int app,result,i,count=0;
long int n;
scanf("%ld\n",&n);
app=(int
)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
scanf("%d",&app[i]);
}
qsort(app,n,sizeof(int),cmpfunc);
result=chef(app,n-1,count);
printf("\n%d\n",result);
}
}
int chef(int *add,long int a,int count)
{
if(a==0) return(count+1);

else if(add[a]==add[a-1]) chef(add,a-1,count);
else if(add[a]>add[a-1])
{
count++;
chef(add,a-1,count);
}
}

@prakhaarsiinha
You cannot ask a question related to an ongoing contest. Plz do read the rules here:-
Rules.
Wait for the contest to end,then you can surely discuss:)
Till then try yourself.

Undeleted…

hey @prakhaarsiinha! you have to add return 0; in your code.
main() should have return 0 to identify that the program has executed successfully. :slight_smile:

@prakhaarsiinha app=(int)malloc… is wrong. app is an int . u can’t customary allocate memory to it.
use int * app;app=(int*)malloc instead.