+ 1
Wap to print sum of given series
1+11+111+.......+n
6 ответов
+ 3
for(int I=0;I<n;I++)
{
s=s+(int)(Math.pow(10,I));
p=p+s;
}
print p as answer
+ 1
very very thanks
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...
0
My mistake..... My suggestion is wrongg
0
Use this instead:
Sum of [(n-k)*10^k]
for k=0,1,2...(n-1)
and n=1,2,3....
I guess
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...