Please calculate the sum of: | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please calculate the sum of:

1+(2/1)+(3/2)+(4/3)+(5/4)+...+(10/9) with any loops.

26th Jul 2020, 7:41 PM
TeaserCode
4 Answers
+ 3
int n = 10; double sum = 0.0; for(int i=1;i<=n;i++){ sum += i / Math.max(1, i-1); }
26th Jul 2020, 8:13 PM
Anton Böhler
Anton Böhler - avatar
+ 2
Sorry, I misunderstood your question.
26th Jul 2020, 7:52 PM
Kevin ★
0
Yes, I was trying. I know it is possible with for loop. First you have find out relation between loop variable and the expression. Here I was stoped.
26th Jul 2020, 7:50 PM
TeaserCode
0
Kevin, please try with loop.
26th Jul 2020, 7:50 PM
TeaserCode