Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. struct punct{int x,y;};
  2.  
  3. void citire (punct *p)
  4. {
  5. printf("\nx=");
  6. scanf("%d",&p->x);
  7. printf("\ny=");
  8. scanf("%d",&p->y);
  9. }
  10. void afisare(punct *p)
  11. {
  12. printf("\np.x=%d",p->x);
  13. printf("\np.y=%d",p->y);
  14. }
  15. double distanta(punct &a,punct &b)
  16. {
  17. double dist;
  18. dist=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  19. return dist;
  20. }
  21.  
  22. int main ()
  23. {
  24. punct p1,p2,pct[N],*pp;
  25. int i,dim;
  26. double dist;
  27. printf("Citire p1:\n");
  28. citire(&p1);
  29. citire(&p2);
  30. afisare(&p1);
  31. afisare(&p2);
  32. printf("\nDistanta=%.2f",distanta(p1,p2));
  33. printf("dim=");scanf("%d",&dim);
  34. pp=new punct[dim];
  35. printf("Coordonatele sunt: \n");
  36. for(i=0;i<dim;i++)
  37. {
  38. citire(&pp[i]);
  39. afisare(&pp[i]);
  40. distanta(pp[i],pp[i+1]);
  41. }
  42.  
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement