Advertisement
MeehoweCK

Untitled

Apr 16th, 2021
804
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*Napisz program, który pobiera od użytkownika liczby całkowite dotąd aż poda on liczbę 0.
  6. Następnie program ma wypisać na ekran średnią arytmetyczną wpisanych liczb (0 ma być liczone).*/
  7.  
  8. int main()
  9. {
  10.     int liczba;
  11.     unsigned licznik = 0;
  12.     int suma = 0;
  13.  
  14.     do
  15.     {
  16.         cin >> liczba;
  17.         ++licznik;
  18.         suma += liczba;
  19.     } while(liczba != 0);
  20.  
  21.     cout << "Srednia podanych liczb wynosi " << 1.0 * suma / licznik << endl;
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement