Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- struct Data {
- int x[50];
- int y[50];
- int opseg;
- };
- int distance(int &x1, int &y1, int &x2, int &y2)
- {
- int x,y,distance;
- //-----------
- if(x1>x2)
- x=x1-x2;
- else if(x2>x1)
- x=x2-x1;
- //-----------
- if(y1>y2)
- y=y1-y2;
- else if(y2>y1)
- y=y2-y1;
- //-----------
- if(x1==x2)
- return y;
- if(y1==y2)
- return x;
- //-----------
- distance=sqrt((x*x) + (y*y));
- return distance;
- }
- int main()
- {
- struct Data p;
- int stranica[3],rez;
- for(int j=0;j<3;j++)
- {
- for(int k=0;k<1;k++)
- {
- printf("\nUnesite koordinate za %d. tocku: X: ",j+1);
- scanf("%d",&p.x[j]);
- printf("\nUnesite koordinate za %d. tocku: Y: ",j+1);
- scanf("%d",&p.y[j]);
- }
- }
- //printf("\n%d. tocka: X: %d, Y: %d",i+1,p.coord[i][k]);
- for(int j=0;j<3;j++)
- {
- for(int k=0;k<1;k++)
- {
- printf("\n%d. tocka: X: %d, Y: %d",j+1,p.x[j],p.y[j]);
- if(j<2)
- stranica[j]= distance(p.x[j],p.y[j],p.x[j+1],p.y[j+1]);
- else
- stranica[j]= distance(p.x[j],p.y[j],p.x[0],p.y[0]);
- }
- }
- rez=stranica[0]+stranica[1]+stranica[2];
- printf("\nRezultat: %d",rez);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement