Safiron

Verča

Apr 3rd, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // rekurzivni metoda
  6. int countToTen(int x)
  7. {
  8.     x++;
  9.     if (x == 10)
  10.     {
  11.         return x;
  12.     }
  13.     else
  14.     {
  15.         return countToTen(x);
  16.     }
  17. }
  18.  
  19.  
  20. // metoda s cyklem
  21. int y;
  22.  
  23. int countToTen()
  24. {
  25.     while(y < 10)
  26.     {
  27.         y++;
  28.     }
  29.     return y;
  30. }
  31.  
  32. int main()
  33. {
  34.  
  35.     cout << "vypis cisla deset pomoci rekurze: " << countToTen(0) << endl;
  36.     cout << "vypis cisla deset pomoci cyklu: " << countToTen() << endl;
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment