- 4

Find the sum of the series s=1+(½)²+(⅓)³+.......to 0.0001% accuracy using c

8th Nov 2020, 10:11 AM
Jeeva Vasudev
Jeeva Vasudev - avatar
3 Respostas
+ 9
Hello Jeeva Vasudev, Please use the Q/A section for ACTUAL questions related to programming or sololearn. You can use your feed or code playground to post something like this Thanks! https://www.sololearn.com/discuss/1316935/?ref=app
8th Nov 2020, 10:37 AM
Simba
Simba - avatar
+ 4
Jeeva Vasudev it would be great if you can copy and paste the code into code bits and then post it here. Anyway you want a precision of 0.0001% that is 1/1000000 (6 zeros) of your order of magnitude, which is 1. So the "n" variable in your code need to be at least 1000000. And you need to show at least 6 decimal digits.So %.6f Another thing to fix is that you don't have to do pow(i,i), do just: ser = 1 / i; For the rest your program is fine. If you want you can do: ser = ser + 1 / i; And you don't need "sums" anymore. You can return "ser" edit: I tried the program and actually there's another thing to fix. it should be: ser = 1.0 / i; otherwise ser gets Always 0 from 2 on, because 1/2 = 0 while 1.0/2 = 0.5
8th Nov 2020, 10:39 AM
Davide
Davide - avatar
- 3
#include <math.h> #include <stdio.h> double Series(int n) { int i; double sums = 0.0, ser; for (i = 1; i <= n; ++i) { ser = 1 / pow(i, i); sums += ser; } return sums; } // Driver Code int main() { int n = 3; double res = Series(n); printf("%.5f", res); return 0; }
8th Nov 2020, 10:19 AM
Jeeva Vasudev
Jeeva Vasudev - avatar