Ramanujan Method C++


#include<bits/stdc++.h>
using namespace std;

double arr1[100];
double arr2[100];
double DIV[100];


double find_B(int n)
{
    double sum=0.0;

    for(int i=1;i<n;i++)
    {

        sum = sum + (1.0*arr1[i]*arr2[n-i]);

    }

    return sum;
}

void div()
{
    cout<<" n\t DIV\n"<<endl;
    for(int i=1;i<10;i++)
    {
        DIV[i]=(arr2[i]/(1.0*arr2[i+1]));
    }

    cout<<"\n";
}


int main()
{
    double x,a,b,c,d;
    double fx;

    cout<<"Equation's Co-efficients"<<endl;

    cout<<"Enter Value For x^3 : ";
    cin>>a;
    cout<<"Enter Value For x^2 : ";
    cin>>b;
    cout<<"Enter Value For x : ";
    cin>>c;
    cout<<"Enter Constant :";
    cin>>d;

    arr1[1]= c/(-d);
    arr1[2]= b/(-d);
    arr1[3]= a/(-d);

    arr2[1]=1;

    for(int i=2;i<12;i++)
    {
        arr2[i]=find_B(i);
    }

    div();
    int i;

    for(i=1;i<=10;i++)
    {

        if(fabs(DIV[i]-DIV[i+1])>0.005 && DIV[i+1])
        {
            cout<<endl;
            cout<<i<<"\t "<<DIV[i]<<endl;
            cout<<"......................................."<<endl;
        }
        else
            break;
    }


    cout<<"\n\nRoot is: ";
    cout<<fixed<<setprecision(3)<<DIV[i]<<endl;


    return 0;

}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment