Advertisement
StefiIOE

Tocka lab 1.1

Mar 11th, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. typedef struct point2D {
  4.     double x;
  5.     double y;
  6.  
  7. }
  8. point2D;
  9. float distance (point2D t1, point2D t2) {
  10.  
  11.  
  12.     return sqrt((t1.x-t2.x)*(t1.x-t2.x)+(t1.y-t2.y)*(t1.y-t2.y));
  13.  
  14. }
  15. typedef struct point3D {
  16.     double x;
  17.     double y;
  18.     double z;
  19. }
  20. point3D;
  21. float distance3D(point3D t1, point3D t2) {
  22.  
  23.     return sqrt((t1.x-t2.x)*(t1.x-t2.x)+(t1.y-t2.y)*(t1.y-t2.y)+(t1.z-t2.z)*(t1.z-t2.z));
  24.  
  25. }
  26. int collinear(point2D t1,point2D t2, point2D t3) {
  27.     if((t2.y-t1.y)/(t2.x-t1.x)==(t3.y-t2.y)/(t3.x-t2.x))
  28.         return 1;
  29.     else
  30.         return 0;
  31.  
  32. }
  33. int main() {
  34.     float x1, y1, x2, y2;
  35.     scanf("%f %f", &x1, &y1);
  36.     scanf("%f %f", &x2, &y2);
  37.     point2D t1 = { x1, y1 };
  38.     point2D t2 = { x2, y2 };
  39.     printf("%.2f\n", distance(t1, t2));
  40.     float z1, z2;
  41.     scanf("%f %f", &z1, &z2);
  42.     point3D t3 = {x1, y1, z1};
  43.     point3D t4 = {x2, y2, z2};
  44.     printf("%.2f\n", distance3D(t3, t4));
  45.     point2D t5 = {z1, z2};
  46.     printf("%d\n", collinear(t1, t2, t5));
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement