Advertisement
Maco153

Recursive Function

Nov 13th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int squares(int num) {
  5.  
  6. while (num >= 1) {
  7. if (num == 1){
  8. return 1;
  9. }
  10. else
  11. {
  12. return (pow(num , 2) + squares(num - 1));
  13. }
  14.  
  15. }
  16.  
  17.  
  18.  
  19. }
  20.  
  21. int main() {
  22. int num;
  23. cout << "Enter the number you want to sum the series up to!\n";
  24. cin >> num;
  25. cout << "your sum of series " << squares(num);
  26. return 0;
  27.  
  28.  
  29.  
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement