Question: -----------C------C---------C-------C------------C-------------C------------ Question 4 (40 Points) Please create a triangle structure that contains the edge lengths of a triangle as integers. Hint: You can create a

 -----------C------C---------C-------C------------C-------------C------------ Question 4 (40 Points) Please create a triangle structure that -----------C------C---------C-------C------------C-------------C------------

Question 4 (40 Points) Please create a triangle structure that contains the edge lengths of a triangle as integers. Hint: You can create a struct for your triangles as follows: struct triangle { int a; int b; intc; }; typedef struct triangle triangle; Take an integer n from the user that represents the number of triangles and allocate dynamic memory for your triangles. Hint: You can allocate memory for your triangles as follows: triangle *tri= malloc(n * sizeof(triangle)); Assign random numbers for the lengths of edges of the triangles. Your triangles must satisfy the following constraints: 1 a, ai + i > b and bi +G > ai where ai, biGi, i = 1, ..., 71 represent the edge lengths of the triangles. . Main part: You must sort triangles by their areas from the smallest one to the largest one in allocated memory Hint: The best way to calculate ab area of the triangle with sides a, b and c is Heron's formula: A= s(s-a)(s c)(s - c) where s = (a +b+c)/2 To print your output use the following lines of codes: for (int i=0;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!