Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // wszystkie trzy poniższe pętle robią dokładnie to samo
- int main()
- {
- int liczba = 1;
- int suma = 0;
- while(liczba != 0)
- {
- cin >> liczba;
- suma += liczba;
- cout << suma;
- }
- suma = 0;
- do
- {
- cin >> liczba;
- suma += liczba;
- cout << suma;
- } while(liczba != 0);
- // uwaga: pętla for w poniższym przykładzie wygląda mało "naturalnie". W praktyce używa się jej do innych algorytmów (szczególnie do pracy na tablicach)
- for(suma = 0; liczba != 0; cout << suma)
- {
- cin >> liczba;
- suma += liczba;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement