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.
[
int compute_area(triangle tr){
int p = (tr.a + tr.b + tr.c) / 2;
int s = sqrt(p * (p - tr.a) * (p - tr.b) * (p - tr.c));
return s;
}
int compare(const void *tr1, const void tr2){
int area1 = compute_area((triangle*)tr1);
int area2 = compute_area((triangle)tr2);
return (area1 - area2);
}
void sort_by_area(triangle* tr, int n) {
/**
* Sort an array a of the length n
*/
// Sort the computed area array.
qsort(tr, n, sizeof(triangle), compare);
}](https://)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Small Triangles, Large Triangles
You are viewing a single comment's thread. Return to all comments →
[ int compute_area(triangle tr){ int p = (tr.a + tr.b + tr.c) / 2; int s = sqrt(p * (p - tr.a) * (p - tr.b) * (p - tr.c)); return s; }
int compare(const void *tr1, const void tr2){ int area1 = compute_area((triangle*)tr1); int area2 = compute_area((triangle)tr2); return (area1 - area2); }
void sort_by_area(triangle* tr, int n) { /** * Sort an array a of the length n */ // Sort the computed area array. qsort(tr, n, sizeof(triangle), compare); }](https://)