You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

28 lines
594 B

  1. #include <math.h>
  2. #include <stdio.h>
  3. typedef struct Point {
  4. float x, y;
  5. } Point;
  6. float distance(Point p1, Point p2) {
  7. return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
  8. }
  9. float area(Point A, Point B, Point C) {
  10. return 0.5 * fabsf(A.x * B.y - B.x * A.y + B.x * C.y - C.x * B.y +
  11. C.x * A.y - A.x * C.y);
  12. }
  13. int main() {
  14. Point A = {2.5, 6};
  15. Point B = {1, 2.2};
  16. Point C = {10, 6};
  17. float f = distance(A, B);
  18. printf("A -- B distance is %f\n", f);
  19. float a = area(A, B, C);
  20. printf("Area of triangle ABC is %f\n", a);
  21. }