You are on page 1of 1

#include <iostream>

#include <math.h>
using namespace std;
#define h powf(10,-7)
#define PI 180
float funct(float x){

return cos(x)-x;

}
float derivative (float x){
return (( funct(x+h)-funct(x-h))/(2*h));

}
int main(){
float tol=.001;
int N=3;
float p0=PI/4;
float p=0;
int i=1;
while(i<N){

p=p0-(float)funct(p0)/derivative(p0);
if ((p-p0)<tol){
cout<<p<<endl;
break;

i=i+1;
p0=p;

if (i>=N){
cout<<"solution not found "<<endl;
break;
}
}

return 0;
}

You might also like