Jump to content

C++ Graeffe's square root method help

Featured Replies

So i have to write a c++ program for the Graeffe's square root method
I have am stuck here when i have this formula transform into c++ code, the formula is on the link

The code works particulary, the (elem[j-1]*elem[j+i]) doesn't work, it's beeing ignored and i don't know why... can any one help me?

http://latex.codecogs.com/gif.latex?A_{k}=a_{k}^{2}+2\sum_{s=1}^{k}(-1)^{s}a_{k-s}*a_{k+s},&space;k=0,....n

 

cout<<"How many elements?"<<endl;
cin>>n;
cout<<"Insert x:"<<endl;
for(int i=0; i<n; i++)
{
cin>>elem;

}


C[0]=pow(elem[0],2);

for(int j=1; j<n; j++)
{
C[j]=pow(elem[j],2);

int i=1;
while((i+j)<=n-1&&(i<=j))
{

C[j]=C[j]+(-1)^i*2*(elem[j-1]*elem[j+i]);
i=i+1;

}


cout<<"C"<<j<<":"<<C[j]<<endl;

}

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.