Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I cannot figure out how to make L start with 1. It is supposed to approximate pi

ID: 3541817 • Letter: I

Question

I cannot figure out how to make L start with 1. It is supposed to approximate pi, but it is skipping L = 1 in the calculations and so it isn't multiplying the right n and L in A or R. I'm sure it is a quick fix, but I just cannot see it.


#include <iostream>

#include <cmath>

#include <iomanip>


using namespace std;


int main(void)

{

    cout << std::left<< std::setw(20);

    cout<<"n         "<<"L          "<<"Approximation of PI    " <<"Absolute Error in Approximating PI"<<endl;

    double n;

    double A;

    double R;

    const double PI = 4.0 * atan(1.0);


    for (double i = 0, L = 1; i < 26; i++)

    {

        n = 6 * pow(2, i);

        

        L = sqrt(2 - sqrt(4 - pow(L, 2)));

        A = (n*L)/2;

        R = fabs(((n * L)/2)-PI);

        cout << std::left << std::setw(10);

        cout<<std::setprecision(12);

        cout << n<<"    "<< L<<"      "<<A<<"            "<< R<<endl;

    }

    return 0;

}

Explanation / Answer

Hi in the programe everytime when the for loop start then L is assigned with 1 so the l value is same in all the loops.


There is no concept that its not taking the L value. Here L has only one value that is one.


Please verifyt the logic.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote