Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct el_t
- {
- double liczba;
- el_t *nast;
- };
- void pisz(el_t *w)
- {
- while (w != 0)
- {
- cout << w -> liczba << endl;
- w = w -> nast;
- }
- }
- double srednia(el_t *w)
- {
- double suma = 0;
- int licz = 0;
- while (w != 0)
- {
- suma += w -> liczba;
- licz++;
- w = w -> nast;
- }
- double sred = suma/licz;
- return sred;
- }
- void usun(el_t *g)
- {
- while (g!= 0)
- {
- el_t *pom = g;
- g = g -> nast;
- delete pom;
- }
- }
- int main()
- {
- el_t *g=0, *a=0;
- double x;
- cin >> x;
- while (x > 0.0)
- {
- if (g == 0)
- {
- g = new el_t;
- g -> liczba = x;
- g -> nast = 0;
- a = g;
- }
- else
- {
- a -> nast = new el_t;
- a = a -> nast;
- a -> liczba = x;
- a -> nast = 0;
- }
- cin >> x;
- }
- cout << endl << endl;
- pisz (g);
- cout << endl << endl;
- double sr = srednia(g);
- cout << sr << endl;
- usun(g);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement