Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #define ll long long int
  4.  
  5. ll sum(int n)
  6. {
  7. if(n == 1){
  8. return 1;
  9. }else{
  10. return ((ll)pow(n, n) + sum(n - 1));
  11. }
  12. }
  13.  
  14. void main()
  15. {
  16. int n = 3;
  17. printf("%d", sum(n));
  18. }
  19.  
  20. -------------------------
  21.  
  22.  
  23. At the very beginning the ll ( small L L ) is defined as long long int
  24. which signifies that this function is capable of handling a big number
  25. upto the limit of long long int.
  26.  
  27. n == 1 is the breakout condtion for the function sum,
  28. in which point function stops recursing.
  29.  
  30. If the input is greater than 1, function rturns the n'th power of number n
  31. along with a recursion to itself where input is n - 1.
  32.  
  33. Example:
  34.  
  35. For input of 3
  36.  
  37. sum(3)
  38.  
  39. => 3^3 + sum(2) => 2^2 + sum(1) => 1
  40. => 27 + 4 + 1
  41. = 32
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement