klikaa
-
Posts
5 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by klikaa
-
-
sqrt() the most likely is returning NaN (Not A Number) for negative input.
The same happens with regular hand calculators (E letter appears etc.)
http://en.wikipedia.org/wiki/NaN
It's mentioned on wiki page
"There are three kinds of operations that can return NaN:
[...]
The square root of a negative number."
and how can i change that? that i doesn't give nan ?
0 -
The part
for(int i=1; i<n; i++)
{
x=sqrt(y*i);
cout<<"x"<<i<<": "<<x<<endl;
}isn't working wll, for some elements the result is non, i thought that i because the numbers are complex, but not with include complex i get the same resut.. can anyone help me
#include<iostream> #include<math.h> #include <complex> using namespace std; int main() { int n,elem[20]; float y[20],A[20]; complex<float> x[20]; cout<<"Number of elements?"<<endl; cin>>n; cout<<"Insert elements:"<<endl; for(int i=0; i<n; i++) { cin>>elem[i]; } A[0]=pow(elem[0],2); for(int j=1; j<n; j++) { A[j]=pow(elem[j],2); int i=1; while((i+j)<=n-1&&(i<=j)) { A[j]=A[j]+pow((-1),i)*2*(elem[j-i]*elem[j+i]); i=i+1; } cout<<"A"<<j<<":"<<A[j]<<endl; } for(int i=1; i<n; i++) { y[i]=A[i]/-A[i-1]; cout<<"y"<<i<<": "<<y[i]<<endl; } for(int i=1; i<n; i++) { x[i]=sqrt(y[i]*i); cout<<"x"<<i<<": "<<x[i]<<endl; } }
0 -
thanks, that was the problem ))
1 -
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 linkThe 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?
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;
}0
C++ square problems
in Homework Help
Posted
thanks for you help... i figured it out.. now its all working