+ 1

Wap to print sum of given series

1+11+111+.......+n

9th Jul 2017, 9:11 AM
shakti
6 Answers
+ 3
for(int I=0;I<n;I++) { s=s+(int)(Math.pow(10,I)); p=p+s; } print p as answer
9th Jul 2017, 10:01 AM
Vaibhav Tandon
Vaibhav Tandon - avatar
+ 1
very very thanks
9th Jul 2017, 9:36 AM
shakti
0
You can use classical maths instead... A simple formula (n-1)+(10^n -1)/9 From arithmetic progression by writing it as 1+(10+1)+(100+1)+....... If you want to make it a program, just apply the formula...
9th Jul 2017, 9:34 AM
Ledio Deda
Ledio Deda - avatar
0
My mistake..... My suggestion is wrongg
9th Jul 2017, 9:39 AM
Ledio Deda
Ledio Deda - avatar
0
Use this instead: Sum of [(n-k)*10^k] for k=0,1,2...(n-1) and n=1,2,3.... I guess
9th Jul 2017, 9:43 AM
Ledio Deda
Ledio Deda - avatar
0
Here is the idea (C++) but it cant be too different in java i think https://code.sololearn.com/cm78p58M5sW9/?ref=app Just the algorythm...
9th Jul 2017, 10:00 AM
Ledio Deda
Ledio Deda - avatar