Advertisement
JStefan

[Laboratoriski] Tocka

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