Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double func(double x)
- {
- return cos(x);
- }
- int main()
- {
- double x=1,eps = 0.001,p;
- int i=1,N=1000;
- while(true)
- {
- p = func(x);
- if(fabs(p-x) < eps)
- {
- cout<<p<<endl;
- break;
- }
- cout<<"Iteration "<<i<<": p = "<<p<<endl;
- i++;
- x = p;
- cout<<"The solution is "<<p<<endl;
- if(i>N)
- {
- cout<<"Solution not found"<<endl;
- break;
- }
- }
- cout<<"The solution is x = "<<p<<" in the iteration "<<i-1<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement