0
Write a c++ program for sum of series
3 Réponses
+ 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;
}
+ 1
Hmm, you are right, Rene. i++ or ++i alone is probably translated the same way by the compiler though.
0
@Zen take care: using post-increment on i isn't advised as it will create a unnecessary copy