Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. struct el_t
  5. {
  6. double liczba;
  7. el_t *nast;
  8. };
  9. void pisz(el_t *w)
  10. {
  11. while (w != 0)
  12. {
  13. cout << w -> liczba << endl;
  14. w = w -> nast;
  15. }
  16. }
  17. double srednia(el_t *w)
  18. {
  19. double suma = 0;
  20. int licz = 0;
  21. while (w != 0)
  22. {
  23. suma += w -> liczba;
  24. licz++;
  25. w = w -> nast;
  26. }
  27. double sred = suma/licz;
  28. return sred;
  29. }
  30. void usun(el_t *g)
  31. {
  32. while (g!= 0)
  33. {
  34. el_t *pom = g;
  35. g = g -> nast;
  36. delete pom;
  37. }
  38. }
  39.  
  40. int main()
  41. {
  42. el_t *g=0, *a=0;
  43. double x;
  44. cin >> x;
  45. while (x > 0.0)
  46. {
  47. if (g == 0)
  48. {
  49. g = new el_t;
  50. g -> liczba = x;
  51. g -> nast = 0;
  52. a = g;
  53. }
  54. else
  55. {
  56. a -> nast = new el_t;
  57. a = a -> nast;
  58. a -> liczba = x;
  59. a -> nast = 0;
  60. }
  61. cin >> x;
  62. }
  63.  
  64. cout << endl << endl;
  65.  
  66. pisz (g);
  67. cout << endl << endl;
  68. double sr = srednia(g);
  69. cout << sr << endl;
  70. usun(g);
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement