#include <stdio.h>
int summation(int N);
int summation(int N) {
if (N != 0)
return N + summation(N - 1);
elsereturn N;
}
int main(){
int N;
printf("\n Enter a positive number: ");
scanf("%d", &N);
printf("\n Sum = %d", summation(N));
printf("\n\n");
return0;
}

but not

1 + 2 + 4 + 8 + 16 + …

thats 1+2+3+4....n
what ı am

What I have tried:

ı try summution positive number of n
also
ı wanted 1+2+4+8+16+...n
not 1+2+3 ....n
what called ?

#include <bits/stdc++.h>
usingnamespace std;
// function to calculate sum of series int calculateSum(int n)
{
// initialize sum as 0 int sum = 0;
// loop to calculate sum of series for (int i = 0; i < n; i++) {
// calculate 2^i // and add it to sum
sum = sum + (1 << i);
}
return sum;
}
// Driver code int main()
{
int n = 10;
cout << "Sum of series of power of 2 is : "
<< calculateSum(n);
}