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.
voidsort_by_area(triangle*tr,intn){// Sort an array a of the length nint*p=malloc(n*sizeof(int));//create array of size n to store "volumes"for(inti=0;i<n;i++){floata=(tr[i].a+tr[i].b+tr[i].c)/2.0;//use 2.0 compulsary int/int gives int, int/float gives floatp[i]=(a*(a-tr[i].a)*(a-tr[i].b)*(a-tr[i].c));//formula without sqrt as areas are different guarenteed //because sqrt dosent work well with float values}//bubble sortfor(inti=0;i<n;i++){for(intj=0;j<n-i-1;j++){if(p[j]>p[j+1]){inttemp=p[j];p[j]=p[j+1];p[j+1]=temp;//swapping array of areas in ascending//and simuntaneously the structure contentstemp=tr[j].a;tr[j].a=tr[j+1].a;tr[j+1].a=temp;temp=tr[j].b;tr[j].b=tr[j+1].b;tr[j+1].b=temp;temp=tr[j].c;tr[j].c=tr[j+1].c;tr[j+1].c=temp;}}}}
Simple straight logic
array p is declared dynamically also can use //int p[1000];
Small Triangles, Large Triangles
You are viewing a single comment's thread. Return to all comments →
Simple straight logic
array p is declared dynamically also can use //int p[1000];
Don't manipulate anything else