+ 1

How to print the sum of series= x/1-x/2+x/3-x/4.....n

plz tell tomorrow is my exam

21st Mar 2018, 11:13 PM
Daily Profit Zone
10 Respuestas
+ 21
it can be written as x(1- 1/2 + 1/3 - 1/4 + 1/5 ...) so U just need to run a loop for accounting that & then multiply that with x in last double prdct=0; for (int a=1;a =<n;a++) prdct+=prdct/a; System.out.println(prdct*x); 👉here , I have taken prdct in double bcz int/int is always an integer in java //btw can be done directly using math
22nd Mar 2018, 3:14 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
22nd Mar 2018, 7:18 AM
Satyam Anand
Satyam Anand - avatar
22nd Mar 2018, 7:18 AM
Satyam Anand
Satyam Anand - avatar
0
https://code.sololearn.com/Wu6sPJIYW4ma/?ref=app something like this?
21st Mar 2018, 11:41 PM
Roel
Roel - avatar
0
no brother just simple java language with for loop . I'm in 10th standard
21st Mar 2018, 11:48 PM
Daily Profit Zone
0
sorry but i dont understand you
21st Mar 2018, 11:51 PM
Roel
Roel - avatar
0
like this: int i,s=0; for(i=1;1<=n;1++) { sum=sum+... this was just for demo hope u understood the concept. Plz help
21st Mar 2018, 11:53 PM
Daily Profit Zone
0
try sum+= sum
22nd Mar 2018, 12:46 AM
Roel
Roel - avatar
0
sorry but im very bad at java
22nd Mar 2018, 12:46 AM
Roel
Roel - avatar
0
or sum++
22nd Mar 2018, 12:46 AM
Roel
Roel - avatar