We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Small Triangles, Large Triangles
Small Triangles, Large Triangles
Sort by
recency
|
426 Discussions
|
Please Login in order to post a comment
hello, my code give me run time error each time can you help me?
Here is my solution that generates and sorts a list as it processes each triangle
9/11 test cases failed, 2 test case pass:
where i'm wrong
double area(triangle tr){ double s = (double)(tr.a + tr.b + tr.c)/2; return sqrt(s * (s - tr.a) * (s - tr.b) * (s - tr.c)); }
// using bubble sort algo.... void sort_by_area(triangle* tr, int n) { /** * Sort an array a of the length n */
}~
**where am i goin wrong **
void sort_by_area(triangle* tr, int n) { int i,j,min_area_index; double *min_area,p,area; min_area=(double)malloc(sizeof(double)); area=(double*)malloc(sizeof(double)); triangle gr; *min_area=0.000000; for(i=0;imin_area=(double)(p(p-tr[i].a)(p-tr[i].b)(p-tr[i].c)); min_area_index=i; for(j=i+1;jarea=((double)(p(p-tr[j].a)(p-tr[j].b)(p-tr[j].c))); if(*area<*min_area) min_area_index=j;
} gr=tr[i]; tr[i]=tr[min_area_index]; tr[min_area_index]=gr; }
}