Advertisement
Guest User

Statki

a guest
Jan 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. struct statek{int,x,y; struct statek* nast;};
  2. typedef struct statek STATEK;
  3. STATEK *pierwszy;
  4.  
  5. //pierwszy->x = 3;
  6. //pierwszy->y=5;
  7.  
  8. //pierwszy->nast->x=7;
  9. //pierwszy->nast->y=8;
  10.  
  11. Lista funkcja (Lista pierwszy, int x0, int y0)
  12. {
  13. int licznik = 0;
  14. double suma = 0;
  15. double srednia;
  16.  
  17. Statek* pom = pierwszy;
  18.  
  19. while (pom!=NULL)
  20. {
  21. suma = suma + sqrt((pom->x - x0)*(pom->x - x0) + (pom->y - y0)*(pom->y*y0));
  22. licznik++;
  23. pom = pom->nast;
  24. }
  25. srednia = suma/licznik;
  26.  
  27. STATEK* nowa;
  28. STATEK* pom2 = nowa;
  29. pom = pierwszy;
  30. while (pom!=NULL)
  31. {
  32. if (sqrt((pom->x - x0)*(pom->x - x0) + (pom->y - y0)*(pom->y*y0)) <= srednia)
  33. {
  34. pom2 = malloc(sizeof(STATEK));
  35. *pom2 = *pom;
  36. pom2->nast=NULL;
  37. }
  38. pom=pom->nast;
  39.  
  40. }
  41.  
  42. pom = pierwszy;
  43.  
  44. while (pom!=NULL)
  45. {
  46. if (sqrt((pom->x - x0)*(pom->x - x0) + (pom->y - y0)*(pom->y*y0)) > srednia)
  47. {
  48. pom2 = malloc(sizeof(STATEK));
  49. *pom2 = *pom;
  50. pom2->nast=NULL;
  51. }
  52. pom=pom->nast;
  53.  
  54. }
  55.  
  56.  
  57. return nowa;
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement