neogz

Suma kvadrata od m-n//dekompoozicija

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