Small Triangles, Large Triangles

  • + 0 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;
    
            }
    
        }
    
    }
    

    }