Geometric Sum
Send Feedback
1 + 1/2 + 1/4 + 1/8 + ... + 1/(2^k)
Integer k
Geometric sum
0 <= k <= 1000
3
1.875
4
1.93750
SOLUTION:-
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
double geometricSum(int k) {
// Write your code here
if(k==0)
return 1;
else{
double sump= (1/(pow(2,k)));
return geometricSum(k-1)+sump;
}
}
int main() {
int k;
cin >> k;
cout << fixed << setprecision(5);
cout << geometricSum(k) << endl;
}
This is dummy text. It is not meant to be read. Accordingly, it is difficult to figure out when to end it. But then, this is dummy text. It is not meant to be read. Period.
If you have any doubts then please let me know... ConversionConversion EmoticonEmoticon