Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4.  
  5. struct Data {
  6.     int x[50];
  7.     int y[50];
  8.     int opseg;
  9. };
  10.  
  11.  
  12. int distance(int &x1, int &y1, int &x2, int &y2)
  13. {
  14.     int x,y,distance;
  15.     //-----------
  16.     if(x1>x2)
  17.         x=x1-x2;
  18.     else if(x2>x1)
  19.         x=x2-x1;
  20.     //-----------          
  21.     if(y1>y2)
  22.         y=y1-y2;
  23.     else if(y2>y1)
  24.         y=y2-y1;
  25.     //-----------
  26.     if(x1==x2)
  27.         return y;
  28.        
  29.     if(y1==y2)
  30.         return x;
  31.     //-----------
  32.     distance=sqrt((x*x) + (y*y));
  33.     return distance;
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39.     struct Data p;
  40.    
  41.     int stranica[3],rez;
  42.    
  43.     for(int j=0;j<3;j++)
  44.     {
  45.         for(int k=0;k<1;k++)
  46.         {
  47.             printf("\nUnesite koordinate za %d. tocku: X: ",j+1);
  48.             scanf("%d",&p.x[j]);
  49.            
  50.             printf("\nUnesite koordinate za %d. tocku: Y: ",j+1);
  51.             scanf("%d",&p.y[j]);
  52.         }
  53.     }
  54.     //printf("\n%d. tocka: X: %d, Y: %d",i+1,p.coord[i][k]);
  55.     for(int j=0;j<3;j++)
  56.     {
  57.         for(int k=0;k<1;k++)
  58.         {
  59.             printf("\n%d. tocka: X: %d, Y: %d",j+1,p.x[j],p.y[j]);
  60.             if(j<2)
  61.                 stranica[j]= distance(p.x[j],p.y[j],p.x[j+1],p.y[j+1]);
  62.             else
  63.                 stranica[j]= distance(p.x[j],p.y[j],p.x[0],p.y[0]);
  64.         }
  65.     }
  66.     rez=stranica[0]+stranica[1]+stranica[2];
  67.     printf("\nRezultat: %d",rez);  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement