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.
#include<stdio.h>#include<stdlib.h>#include<math.h>structtriangle{inta;intb;intc;};typedefstructtriangletriangle;doublecalculate_area(triangletr){doubles=(tr.a+tr.b+tr.c)/2.0;returnsqrt(s*(s-tr.a)*(s-tr.b)*(s-tr.c));}intcompare(constvoid*a,constvoid*b){triangle*tr1=(triangle*)a;triangle*tr2=(triangle*)b;doublearea1=calculate_area(*tr1);doublearea2=calculate_area(*tr2);if(area1<area2)return-1;if(area1>area2)return1;return0;}voidsort_by_area(triangle*tr,intn){/** * Sort an array a of the length n */qsort(tr,n,sizeof(triangle),compare);}
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 →