+ 2
Root
double root(double c) { double t; t=c; while( abs(t-c/t) > 0.001 ) t=0.5*(t+c/t); return t; } Someone can help me? The error massage tell me that I have a problem with the abs that it's not declared
9 ответов
+ 2
Great! Thanx!!!
+ 1
First number that doesn't divide into it evenly returns true.
+ 1
So what I should write?
0
You so sharp!
0
#include <iostream>
#include <cmath>
using namespace std;
double root(double c)
{
double t;
t=c;
while( abs(t-c/t) > 0.001 )
t=0.5*(t+c/t);
return t;
}
bool Prime(int b)
{
int i;
if(b==0 || b==1)
return false;
else
for(i=2; i<root(b); i++)
{
if( b%i == 0 )
return false;
else
return true;
}
}
int main ()
{
int n;
cout<<"Please enter a num ";
cin>>n;
cout<<n<<endl;
cout<<"does your number is Primery? "<<Prime(n)<<endl;
return 0;
}
Now, can you tell me why for every number its return true?
0
I didn't understand
0
Ohh, exactly, that the problem
0
for(i=2; i<root(b); i++)
{
if( b%i == 0 )
return false;
else
return true;
}
b = 9; first loop i= 2, 9%2 is 1 so else path returns true
0
for(i=2; i<root(b); i++)
{
if( b%i == 0 )
return false;
}
return true;