Advertisement
daktarism

Basic Iteration Method

Feb 26th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double h(double a){return (  1 + 2*sin(a/57.2957795)  ) / 2;}
  5.  
  6. int main(void)
  7. {
  8.      double xsifir, epsilon, fark;
  9.      printf( "X0 = " ); scanf( "%lf" , &xsifir );
  10.      printf( "epsilon = " ); scanf( "%lf" , &epsilon );
  11.  
  12.      printf( abs( cos( xsifir/57.2957795 )  < 1)  ? "\nYakinsaktir.\n\n" : "\nIraksaktir.\n\n");
  13.  
  14.      do{
  15.         fark = xsifir-h(xsifir);
  16.         printf("fark = %.20lf , kok = %.16lf\n", fark, h(xsifir));
  17.         if( fark > epsilon ){ xsifir = h(xsifir); }
  18.      } while ( fark > epsilon );
  19.  
  20.      return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement