×

# include<stdio.h>

int main() { int n, h[20],i,d=0,k,j; printf("\nNo of Students: "); scanf("%d",&n); printf("\nHeight of students: "); for (i=0; i<n; i++) scanf("%d",&h[i]); i=0; for (j=0; j<n; j++) { if (h[i]<h[i+1]) {

  i++;

}
else
{
++d;
for (k=0; k<n; k++)
h[k]=h[k+1];
}


}

printf("\noutput is : %d",d); return 0; }

11
accept rate: 0%

Can you please specify which question this code belongs to.

(16 Apr '15, 22:07) 1★

 0 It seems you are allocating less memory,but the question requires more.i.e size of the array.It would have been easy to tell if you would have shared the link of the problem.Because usually run time error comes when you are trying to access those locations which you haven't allocated. Increase the size of the array,or make it h[n];  Hope this helps. Happy Coding!! answered 15 Apr '15, 01:55 206●1●2●9 accept rate: 9%
 0 You are allocating less memory as said above , and you are trying to access the nth index at the end of both of your loops even if you get memory fixed you will get wrong answer so run your loop till n-1. answered 16 Apr '15, 19:46 16●1●1●3 accept rate: 0%
 0 Since you have not specified the question, it's hard to tell exactly. But one of the problems might be h[20]. You might need more than 20. You also have bugs here for (k=0; k
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×545
×280
×231

question asked: 14 Apr '15, 23:42

question was seen: 1,191 times

last updated: 16 Apr '15, 22:19