Small Triangles, Large Triangles

  • + 0 comments

    hello, my code give me run time error each time can you help me?

    void sort_by_area(triangle* tr, int n) 
    {
        int S[n-1];
       for(int i = 0 ; i < n ; i++)
        {
         int p = (tr[i].a + tr[i].b + tr[i].c)/2;
         S[i]=sqrt(p * ( p - tr[i].a ) * ( p - tr[i].b ) * ( p - tr[i].c ) );  
        }
        
        for(int i = 0 ; i < n ; i++ )
        {
          for (int j = 0 ; j < n ; j++ )
          {
            int tempS;
            triangle* temptr = tr;
            if ( S[j] > S[j+1] )
            {
              tempS = S[j];
              *temptr = tr[j];
              S[j]=S[j+1];
              tr[j]=tr[j+1];
              S[j+1] = tempS;
              tr[j+1] = *temptr;
      
            }
          }
        }
        
        
    }