Geometric Sum
#include <bits/stdc++.h>
using namespace std ;
float Gsum(int k){
//base case
if(k==0) return 1 ;
//Recursive case
double smallAns = Gsum(k-1);
//Calculation
return smallAns + 1.0/pow(2,k);
}
int main(){
cout << Gsum(3);
return 0 ;
}
Comments
Post a Comment