0

What is C++ program to calculate the sum of the series 1-1/2+1/3+ . . . +1/999

15th Oct 2017, 5:39 PM
abhishek surin
abhishek surin - avatar
3 Respuestas
+ 1
https://code.sololearn.com/ceAt4JOz943T It's called a harmonic series. Sometimes a number like 999 doesn't work right in the online app because of server limitations, but if you copy the code into a local compiler on your computer it should work fine.
15th Oct 2017, 11:38 PM
MrSkee
0
But it's not working bro!! I tried many times
16th Oct 2017, 2:26 AM
abhishek surin
abhishek surin - avatar
0
#include <iostream> #include <sstream> double harmonicSeries(int pTerms) { double result; for (int i = 1; i <= pTerms; i++) { result += (double)1 / (double)i; result=result*(-1.0); } return result; } int main() { std::cout << std::fixed << harmonicSeries(999); return 0; } Here is the code. Also thanks to @MrSkee, i just modified his code. Also my name is Vaibhav.
31st Dec 2021, 10:37 AM
vaibhav mokale
vaibhav mokale - avatar