0

a FUNCTION seriessum() to solve the series 1+(1+2)+(1+2+3)+(1+2+3+4)+.........n

without array

27th Aug 2016, 8:22 PM
Asim
Asim - avatar
6 Respuestas
+ 2
unsigned sum = 0; for(unsigned i=0; i<=n; ++i) { sum = sum*2 + i; }
27th Aug 2016, 9:10 PM
Stefan
Stefan - avatar
0
didn't check, just from the mind, something like this?? : for(int i=1; i<=n;++I) sum+= I * (n -I +1);
27th Aug 2016, 8:56 PM
Ernst Maurer
Ernst Maurer - avatar
0
I would do it like this: unsigned sum = 0; for (unsigned i=0; i<n; ++i) { sum += (n-i)*(i+1); }
27th Aug 2016, 10:18 PM
Nelson Urbina
Nelson Urbina - avatar
0
n!
28th Aug 2016, 2:06 AM
Vicente Hernández Pérez
Vicente Hernández Pérez - avatar
0
int result = (n*n*n+3*n*n+2*n)/6; actually not safe from overflow.
28th Aug 2016, 3:16 AM
kiwiyou
kiwiyou - avatar