/* 1.Write the sum of 1/(2^i) for i ranging from 0 to 2. 2.Later generalise it to i ranging from 0 to N where N is a user defined input. 3.Challenge: Calculate 2^i without using pow function. */ #include #include using namespace std; int main( ) { int i =1 ; double s= 0.0 ;// declaration for (i=0 ; i<= 2 ; ++i) { //s = s + user_function(s, i) ; // for task 3. s = s + pow (0.5,i); // ( 0.0 + 0.5^0) i=0, s=1 cout << "sum = " << s << endl; }//for- loop return 0; }