a. Write a function which takes as parameters the x and y co-ordinates of two po
ID: 3639730 • Letter: A
Question
a. Write a function which takes as parameters the x and y co-ordinates of two point, and returns the length of the line segment joining the two points.float lineseg_length (float x1, float y1, float x2, float y2) ;
b. Write a function that takes as parameters the lengths of three sides of a triangle and returns the area of the triangle.
float areasides (float s1, float s2, float s3) ;
c. Write a function that takes as parameters the co-ordinates of the three vertices of a triangle and returns the area of the triangle. To do so, this function must call the above functions.
float areavertices (float x1, float y1, float x2, float y2, float x3, y3) ;
d. Write a main ( ) function that takes as input from the user the co-ordinates of FOUR points A, B, C and D. Then you must call the above functions to find the areas of ABD and CBD, and therefore find the area of the quadrilateral ABCD and print it.
Submit the C program in the file quadarea.c
Explanation / Answer
#include #include float lineseg_length (float x1, float y1, float x2, float y2); float areasides (float s1, float s2, float s3) ; float areavertices (float x1, float y1, float x2, float y2, float x3, float y3) ; int main() { float x1,x2,x3,x4,y1,y2,y3,y4,areaquadrilateral; { printf("enter the cordinate of point P(x1,y1) "); scanf("%f%f", &x1,&y1); printf("enter the cordinate of point Q(x2,y2) "); scanf("%f%f", &x2,&y2); printf("enter the cordinate of pint R(x3,y3) "); scanf("%f%f", &x3,&y3); printf("enter the cordinate point of S(x1,y1) "); scanf("%f%f", &x4,&y4); areaquadrilateral=areavertices(x1,y1,x2,y2,x3,y3)+areavertices(x2,y2,x3,y3,x4,y4); printf("the area of a quadrilateral PQRS = %f ", areaquadrilateral); } return 0; } float lineseg_length (float x1, float y1, float x2, float y2) { float l; l=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); return l; } float areasides (float s1, float s2, float s3) { float s,areatriangle; s=(s1+s2+s3)/2; areatriangle=sqrt(s*(s-s1)*(s-s2)*(s-s3)); return (areatriangle); } float areavertices (float x1, float y1, float x2, float y2, float x3, float y3) { float answer; answer=areasides(lineseg_length(x1,y1,x2,y2),lineseg_length(x2,y2,x3,y3),lineseg_length(x3,y3,x1,y1)); return (answer) ; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.