C++ Graeffe's square root method
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 code works particulary, the bolded part doesn't, 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
cout<<"How many elements?"<<endl;
cin>>n;
cout<<"Insert the elements:"<<endl;
for(int i=0; i<n; i++)
{
cin>>elem[i];
}
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;
}
|
Topic archived. No new replies allowed.