neogz

rekurzija sabiranje dok se ne unese 0

Apr 1st, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.25 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int f()
  5. {  
  6.     int n;
  7.     cout << "Unesite n: ";
  8.     cin >> n;
  9.     if (n == 0) return 0;
  10.     else return n + f();
  11.    
  12.    
  13. }
  14.  
  15. int main()
  16. {
  17.     cout << "SUMA UKUPNO JE = " << f();
  18.  
  19.     system("pause >nul");
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment