You are not logged in. Please login at www.codechef.com to post your questions!

×

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(nsizeof(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); } }

asked 07 Dec '14, 23:54

prakhaarsiinha's gravatar image

2★prakhaarsiinha
-31
accept rate: 0%

Undeleted...

(15 Dec '14, 20:32) betlista ♦♦3★

@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.

link

answered 08 Dec '14, 00:15

ansh1star033's gravatar image

3★ansh1star033
206129
accept rate: 9%

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

link

answered 15 Dec '14, 21:29

rjohari23's gravatar image

3★rjohari23
779214
accept rate: 14%

@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.

link

answered 15 Dec '14, 21:37

bustyasians's gravatar image

5★bustyasians
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×858
×102

question asked: 07 Dec '14, 23:54

question was seen: 1,217 times

last updated: 15 Dec '14, 21:37