+ 1

To print the sum of tje following series-. S=a/1+a/2+a/3+....+a/n.

please tell me the code

25th Aug 2017, 2:12 PM
Dev
Dev - avatar
2 Respuestas
0
Each time, I consider a and n already declared Python : S = 0 for i in range(1,n+1): S += a/i print(S) C/C++ : double S = 0; unsigned i; for(i = 1; i <= n; ++i) S += 1.*a/i; //C++ : cout<<S<<endl; //C : printf("%f\n",S); Ruby : s = 0 #capital letter is for constant for i in 1..n do s += a/i done puts a
25th Aug 2017, 2:44 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
- 1
Python : sum([a/(1+n) for n in range(n)])
25th Aug 2017, 7:24 PM
VcC
VcC - avatar