Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <math.h>
- #include <stdio.h>
- double F(double x){
- return ( sin(x)-x+1 );
- }
- int main(){
- double eps = 0.00001;
- double a = M_PI/2, b = M_PI;
- double dx = b - a;
- double x = dx / 2;
- int count = 0;
- while ( abs( F(x) ) > eps ){
- dx = dx / 2;
- x = a + dx;
- if ( F(x)*F(b) < 0 )
- a = x;
- else
- b = x;
- }
- printf("Answer: %f", x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement