0

Write a c++ program for sum of series

31st Aug 2016, 10:53 PM
kiranraj
3 Antworten
+ 2
unsigned int seriesSum(unsigned int n) { unsigned int sum = 0; for(unsigned int i=0; i<=n; ++i) { sum = sum*2 + i; } return sum; }
31st Aug 2016, 11:01 PM
Zen
Zen - avatar
+ 1
Hmm, you are right, Rene. i++ or ++i alone is probably translated the same way by the compiler though.
31st Aug 2016, 11:24 PM
Zen
Zen - avatar
0
@Zen take care: using post-increment on i isn't advised as it will create a unnecessary copy
31st Aug 2016, 11:13 PM
René Schindhelm
René Schindhelm - avatar