Advertisement
neogz

REK - Suma kvadrata od 1 do n

Aug 20th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. /*
  2.         Suma kvadrata od 1 do n.
  3. */
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8.  
  9. int rsum(int broj)
  10. {
  11.     if (broj <= 1)return 1;
  12.     return broj * broj + rsum(broj - 1);
  13. }
  14.  
  15. int main(){
  16.  
  17.     int broj;
  18.     cout << "Unesite broj: ";
  19.     cin >> broj;
  20.  
  21.     cout << "Suma kvadrata od 1 do " << broj << " = " << rsum(broj) <<endl;
  22.    
  23.     system("pause>null");
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement