neogz

Suma kvadrata od m-n // uzlazna rekurzija

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