Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- #define ll long long int
- ll sum(int n)
- {
- if(n == 1){
- return 1;
- }else{
- return ((ll)pow(n, n) + sum(n - 1));
- }
- }
- void main()
- {
- int n = 3;
- printf("%d", sum(n));
- }
- -------------------------
- At the very beginning the ll ( small L L ) is defined as long long int
- which signifies that this function is capable of handling a big number
- upto the limit of long long int.
- n == 1 is the breakout condtion for the function sum,
- in which point function stops recursing.
- If the input is greater than 1, function rturns the n'th power of number n
- along with a recursion to itself where input is n - 1.
- Example:
- For input of 3
- sum(3)
- => 3^3 + sum(2) => 2^2 + sum(1) => 1
- => 27 + 4 + 1
- = 32
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement