+ 1

C++ / pow

Hi guys ! In C++ , How can I find the summation of a number powered from 1 to (n) ... I mean like the sum of : (2^1)+(2^2)+....+(2^n) Let n=3 so that our result should be = 13

17th Nov 2018, 12:30 AM
ONeal Brown
ONeal Brown - avatar
1 Odpowiedź
+ 2
Hey ONeal Brown this is a great question You have to use a header file math.h and then use pow keyword in the loop(for loop) and place a format in it. Like a+=pow(2,i) where i is the variable use in for loop.
18th Nov 2018, 3:59 AM
Sahil Verma [Inactive]
Sahil Verma [Inactive] - avatar