Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int power(int base, int exponent) {
  5.     if(exponent == 0) {
  6.         return 1;
  7.     }
  8.     return base * power(base, exponent - 1);
  9. }
  10. int sum(int x) {
  11.     if(x == 1) {
  12.         return power(1, 1);
  13.     }
  14.     return power(x, x) + sum(x - 1);
  15. }
  16. int main()
  17. {
  18.     int n;
  19.     cin >> n;
  20.     cout << sum(n) << endl;
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement