How do you write a c program to find out the sum of series of following 1/(1^3)+1/(2^3)+1/(3^3)+........1/(n^3)?

1 Answers

Ray Dart Profile
Ray Dart answered

#include <math.h>

using namespace std;

int main(int argc, char* argv[], char* envp[])

{

        long lRoot = 1;

// sum of terms

        float fSum = 0.0f;

// to test whether value has changed since last iteration

        float fChecksum = 0.0f;

//mainloop

        do

        {

                fChecksum=fSum;

                fSum=fSum + (1 / pow (lRoot, 3));

                lRoot++;

        }

        while (fSum != fChecksum)

        cout << fSum << endl;

        return 0;

}

Before someone flames me that the equality test is flawed because of rounding errors. I already know.

I also realise that this is strictly-speaking, c++ and not c. Only the output to stdout needs changing though, simple to do, I think. And I can't be bothered.




Answer Question

Anonymous