neogz

Suma brojeva djelivih sa 3 od 0-n /v1

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