You are viewing a single comment's thread. Return to all comments →
Epihany. having a separate function for calculating area makes the code much simpler to understand and implement...
float calcArea (triangle tr) //func for cleaner code to calculate the area
{ float p = (tr.a + tr.b + tr.c) / 2.0;
return sqrt (p * (p - tr.a) * (p - tr.b) * (p - tr.c));
}
void sort_by_area(triangle* tr, int n)
{
for (int i = 0; i < n - 1; i++) { for (int j = 0; j - n - 1; j++) { if(calcArea(tr[j]) > calcArea(tr[j+1])) { triangle temp = tr[j]; tr[j] = tr[j+1]; tr[j+1] = temp; } } }
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 →
Epihany. having a separate function for calculating area makes the code much simpler to understand and implement...
float calcArea (triangle tr) //func for cleaner code to calculate the area
{ float p = (tr.a + tr.b + tr.c) / 2.0;
}
void sort_by_area(triangle* tr, int n)
{
}