klikaa Posted January 26, 2014 Posted January 26, 2014 So i have to write a c++ program for the Graeffe's square root methodI 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; }
Sensei Posted January 26, 2014 Posted January 26, 2014 (edited) C[j]=C[j]+(-1)^i*2*(elem[j-1]*elem[j+i]); value ^ power is not working in C/C++ the way as in math. It's bitwise xor operator.. http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B Edited January 26, 2014 by Sensei 2
Endy0816 Posted January 26, 2014 Posted January 26, 2014 (edited) -snip Edited January 26, 2014 by Endy0816
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now